commit 834b591e58a58ccf0612ed16937d86b0c4b8e210 Author: Ben Rohlfs Date: Tue Oct 13 16:52:24 2020 +0200 Do not add reviewer to the attention set when they add themselves Only do that, if they add themselves without sending a comment or vote. Generally do not add the owner/uploader, if the user only adds reviewers without doing anything else. The owner/uploader can only be required to act, if the user actually sends a comment or a vote. Change-Id: Ic98faf3714baf10f94382554be13fb45955878ba diff --git a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts index 50bf411..ca6e99e 100644 --- a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts +++ b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts @@ -950,7 +950,9 @@ export class GrReplyDialog extends KeyboardShortcutMixin( '_ccs.*', 'change', 'draftCommentThreads', - '_includeComments' + '_includeComments', + '_labelsChanged', + 'draft' ) _computeNewAttention( currentUser?: AccountInfo, @@ -961,7 +963,9 @@ export class GrReplyDialog extends KeyboardShortcutMixin( ccs?: PolymerDeepPropertyChange, change?: ChangeInfo, draftCommentThreads?: CommentThread[], - includeComments?: boolean + includeComments?: boolean, + _labelsChanged?: boolean, + draft?: boolean ) { if ( currentUser === undefined || @@ -977,6 +981,10 @@ export class GrReplyDialog extends KeyboardShortcutMixin( // The draft comments are only relevant for the attention set as long as the // user actually plans to publish their drafts. draftCommentThreads = includeComments ? draftCommentThreads : []; + const hasDraft = draftCommentThreads.length > 0 || !!draft; + const hasVote = !!_labelsChanged; + const isOwner = this._isOwner(currentUser, change); + const isUploader = this._uploader?._account_id === currentUser._account_id; this._attentionCcsCount = removeServiceUsers(ccs.base).length; this._currentAttentionSet = new Set( Object.keys(change.attention_set || {}).map( @@ -991,24 +999,21 @@ export class GrReplyDialog extends KeyboardShortcutMixin( ); // Remove the current user. newAttention.delete(currentUser._account_id); - // Add all new reviewers. + // Add all new reviewers, but not the current reviewer, if they are also + // sending a draft or a label vote. + const notIsReviewerAndHasDraftOrLabel = (r: AccountInfo) => + !(r._account_id === currentUser._account_id && (hasDraft || hasVote)); reviewers.base .filter(r => r._pendingAdd && r._account_id) + .filter(notIsReviewerAndHasDraftOrLabel) .forEach(r => newAttention.add(r._account_id!)); - // Add the uploader, if someone else replies. - if ( - this._uploader && - this._uploader._account_id !== currentUser._account_id - ) { - // An uploader must have an _account_id. - newAttention.add(this._uploader._account_id!); - } - // Add the owner, if someone else replies. Also add the owner, if the - // attention set would otherwise be empty. - if (change.owner) { - if (!this._isOwner(currentUser, change)) { - // A change owner must have an _account_id. - newAttention.add(change.owner._account_id!); + // Add owner and uploader, if someone else replies. + if (hasDraft || hasVote) { + if (this._uploader?._account_id && !isUploader) { + newAttention.add(this._uploader._account_id); + } + if (change.owner?._account_id && !isOwner) { + newAttention.add(change.owner._account_id); } } } else { diff --git a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog_test.js b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog_test.js index 7af3792..7a89f3d 100644 --- a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog_test.js +++ b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog_test.js @@ -283,6 +283,33 @@ suite('gr-reply-dialog tests', () => { checkComputeAttention('MERGED', 1, [22, 33], 1, [22, 33], [], [22, 33]); }); + test('computeNewAttention when adding reviewers', () => { + const user = {_account_id: 1}; + const reviewers = {base: [ + {_account_id: 1, _pendingAdd: true}, + {_account_id: 2, _pendingAdd: true}, + ]}; + const change = { + owner: {_account_id: 5}, + status: 'NEW', + attention_set: {}, + }; + element.change = change; + element._reviewers = reviewers.base; + flush(); + + element._computeNewAttention(user, reviewers, [], change, [], true); + assert.sameMembers([...element._newAttentionSet], [1, 2]); + + // If the user votes on the change, then they should not be added to the + // attention set, even if they have just added themselves as reviewer. + // But voting should also add the owner (5). + const labelsChanged = true; + element._computeNewAttention( + user, reviewers, [], change, [], true, labelsChanged); + assert.sameMembers([...element._newAttentionSet], [2, 5]); + }); + test('computeNewAttentionAccounts', () => { element._reviewers = [ {_account_id: 123, display_name: 'Ernie'},