From 5155ebaeec2082a0deb2472bf665c194b3d6d5e6 Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 5 Jan 2017 10:55:16 +0100 Subject: [PATCH] Don't show resolved comments when loading editor --- .../track-changes/TrackChangesManager.coffee | 38 +++++++++---------- .../ide/review-panel/RangesTracker.coffee | 13 ------- .../controllers/ReviewPanelController.coffee | 7 ++-- 3 files changed, 22 insertions(+), 36 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/TrackChangesManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/TrackChangesManager.coffee index cd2f79f798..030aa8c252 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/TrackChangesManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/TrackChangesManager.coffee @@ -35,11 +35,11 @@ define [ @$scope.$on "comment:remove", (e, comment_id) => @removeCommentId(comment_id) - @$scope.$on "comment:resolve", (e, comment_id, user_id) => - @resolveCommentId(comment_id, user_id) + @$scope.$on "comment:resolve_thread", (e, thread_id) => + @resolveCommentByThreadId(thread_id) - @$scope.$on "comment:unresolve", (e, comment_id) => - @unresolveCommentId(comment_id) + @$scope.$on "comment:unresolve_thread", (e, thread_id) => + @unresolveCommentByThreadId(thread_id) @$scope.$on "review-panel:recalculate-screen-positions", () => @recalculateReviewEntriesScreenPositions() @@ -90,9 +90,7 @@ define [ @rangesTracker.off "comment:added" @rangesTracker.off "comment:moved" @rangesTracker.off "comment:removed" - @rangesTracker.off "comment:resolved" - @rangesTracker.off "comment:unresolved" - + setTrackChanges: (value) -> if value @$scope.sharejsDoc?.track_changes_as = window.user.id @@ -129,12 +127,6 @@ define [ @rangesTracker.on "comment:removed", (comment) => sl_console.log "[comment:removed]", comment setTimeout () => @_onCommentRemoved(comment) - @rangesTracker.on "comment:resolved", (comment) => - sl_console.log "[comment:resolved]", comment - setTimeout () => @_onCommentRemoved(comment) - @rangesTracker.on "comment:unresolved", (comment) => - sl_console.log "[comment:unresolved]", comment - setTimeout () => @_onCommentAdded(comment) redrawAnnotations: () -> for change in @rangesTracker.changes @@ -187,13 +179,18 @@ define [ removeCommentId: (comment_id) -> @rangesTracker.removeCommentId(comment_id) - resolveCommentId: (comment_id, user_id) -> - @rangesTracker.resolveCommentId(comment_id, { - user_id, ts: new Date() - }) + RESOLVED_THREADS: {} + resolveCommentByThreadId: (thread_id) -> + @RESOLVED_THREADS[thread_id] = true + for comment in @rangesTracker?.comments or [] + if comment.op.t == thread_id + @_onCommentRemoved(comment) - unresolveCommentId: (comment_id) -> - @rangesTracker.unresolveCommentId(comment_id) + unresolveCommentByThreadId: (thread_id) -> + @RESOLVED_THREADS[thread_id] = false + for comment in @rangesTracker?.comments or [] + if comment.op.t == thread_id + @_onCommentAdded(comment) checkMapping: () -> # TODO: reintroduce this check @@ -335,6 +332,9 @@ define [ @broadcastChange() _onCommentAdded: (comment) -> + if @RESOLVED_THREADS[comment.op.t] + # Comment is resolved so shouldn't be displayed. + return if !@changeIdToMarkerIdMap[comment.id]? # Only create new markers if they don't already exist start = @_shareJsOffsetToAcePosition(comment.op.p) diff --git a/services/web/public/coffee/ide/review-panel/RangesTracker.coffee b/services/web/public/coffee/ide/review-panel/RangesTracker.coffee index 8e9607d00a..6ff301e803 100644 --- a/services/web/public/coffee/ide/review-panel/RangesTracker.coffee +++ b/services/web/public/coffee/ide/review-panel/RangesTracker.coffee @@ -63,19 +63,6 @@ load = (EventEmitter) -> break return comment - resolveCommentId: (comment_id, resolved_data) -> - comment = @getComment(comment_id) - return if !comment? - comment.metadata.resolved = true - comment.metadata.resolved_data = resolved_data - @emit "comment:resolved", comment - - unresolveCommentId: (comment_id) -> - comment = @getComment(comment_id) - return if !comment? - comment.metadata.resolved = false - @emit "comment:unresolved", comment - removeCommentId: (comment_id) -> comment = @getComment(comment_id) return if !comment? diff --git a/services/web/public/coffee/ide/review-panel/controllers/ReviewPanelController.coffee b/services/web/public/coffee/ide/review-panel/controllers/ReviewPanelController.coffee index aa993183d7..ccfb012f2a 100644 --- a/services/web/public/coffee/ide/review-panel/controllers/ReviewPanelController.coffee +++ b/services/web/public/coffee/ide/review-panel/controllers/ReviewPanelController.coffee @@ -32,6 +32,7 @@ define [ for comment in thread.messages formatComment(comment) if thread.resolved_by_user? + $scope.$broadcast "comment:resolve_thread", thread_id formatUser(thread.resolved_by_user) $scope.reviewPanel.commentThreads = threads @@ -146,8 +147,6 @@ define [ new_entry = { type: "comment" thread_id: comment.op.t - resolved: comment.metadata?.resolved - resolved_data: comment.metadata?.resolved_data content: comment.op.c offset: comment.op.p } @@ -243,7 +242,7 @@ define [ thread.resolved_by_user = $scope.users[window.user_id] thread.resolved_at = new Date() $http.post "/project/#{$scope.project_id}/thread/#{entry.thread_id}/resolve", {_csrf: window.csrfToken} - $scope.$broadcast "comment:resolve", entry_id, window.user_id + $scope.$broadcast "comment:resolve_thread", entry.thread_id $scope.unresolveComment = (entry, entry_id) -> thread = $scope.reviewPanel.commentThreads[entry.thread_id] @@ -251,7 +250,7 @@ define [ delete thread.resolved_by_user delete thread.resolved_at $http.post "/project/#{$scope.project_id}/thread/#{entry.thread_id}/reopen", {_csrf: window.csrfToken} - $scope.$broadcast "comment:unresolve", entry_id + $scope.$broadcast "comment:unresolve_thread", entry.thread_id $scope.deleteComment = (entry_id) -> $scope.$broadcast "comment:remove", entry_id