예제 #1
0
        public async Task Publish(NewFileDiscussion[] discussions, Dictionary <string, Guid> newCommentsMap, Dictionary <string, Guid> newDiscussionsMap)
        {
            foreach (var discussion in discussions)
            {
                var commentId    = GuidComb.Generate();
                var discussionId = GuidComb.Generate();

                newCommentsMap[discussion.TemporaryId]    = commentId;
                newDiscussionsMap[discussion.TemporaryId] = discussionId;

                var review = _reviewForRevision(discussion.TargetRevisionId);

                var resolvedFileId = _resolveFileId(discussion.FileId);

                var currentRevision = _sessionAdapter.GetRevision(review.RevisionId);
                var prevRevision    = _sessionAdapter.GetPreviousRevision(currentRevision);

                var currentEntry = _sessionAdapter.GetFileHistoryEntry(resolvedFileId, currentRevision);
                var prevEntry    = _sessionAdapter.GetFileHistoryEntry(resolvedFileId, prevRevision);

                _sessionAdapter.Save(new FileDiscussion
                {
                    RevisionId  = review.RevisionId,
                    Id          = discussionId,
                    FileId      = resolvedFileId,
                    File        = PathPair.Make(prevEntry?.FileName ?? currentEntry.FileName, currentEntry.FileName),
                    LineNumber  = discussion.LineNumber,
                    State       = discussion.State.AsCommentState(),
                    RootComment = new Comment
                    {
                        Id = commentId,
                        PostedInReviewId = review.Id,
                        Content          = discussion.Content,
                        CreatedAt        = DateTimeOffset.UtcNow
                    }
                });
            }
        }
        private IEnumerable <(ClientFileId Id, PathPair Path)> UnpackIds(Guid revisionId, List <ClientFileId> fileIds)
        {
            var result = new List <(ClientFileId Id, PathPair Path)>();

            foreach (var clientFileId in fileIds)
            {
                if (clientFileId.PersistentId == Guid.Empty)
                {
                    result.Add((clientFileId, clientFileId.ProvisionalPathPair));
                    continue;
                }

                var currentRevision = _sessionAdapter.GetRevision(revisionId);
                var currentEntry    = _sessionAdapter.GetFileHistoryEntry(clientFileId.PersistentId, currentRevision);

                var prevRevision = _sessionAdapter.GetPreviousRevision(currentRevision);

                var prevEntry = _sessionAdapter.GetFileHistoryEntry(clientFileId.PersistentId, prevRevision);

                result.Add((clientFileId, PathPair.Make(prevEntry?.FileName ?? currentEntry.FileName, currentEntry.FileName)));
            }

            return(result);
        }