Introduce mentions comments chip Find the mention of the currently logged in user in unresolved threads to show in the mention summary chip. Google-bug-id: b/236921879 Screenshot: https://imgur.com/a/sWkt6to Release-Notes: skip Change-Id: I05157fb58e3e5e7b57207aa169ce3947584a34d2
diff --git a/polygerrit-ui/app/utils/comment-util.ts b/polygerrit-ui/app/utils/comment-util.ts index ec9ea19..911c821 100644 --- a/polygerrit-ui/app/utils/comment-util.ts +++ b/polygerrit-ui/app/utils/comment-util.ts
@@ -30,6 +30,7 @@ import {DiffInfo} from '../types/diff'; import {LineNumber} from '../api/diff'; import {FormattedReviewerUpdateInfo} from '../types/types'; +import {extractMentionedUsers} from './account-util'; export interface DraftCommentProps { // This must be true for all drafts. Drafts received from the backend will be @@ -556,3 +557,19 @@ }, ]; } + +function getMentionedUsers(thread: CommentThread) { + return thread.comments.map(c => extractMentionedUsers(c.message)).flat(); +} + +export function getMentionedThreads( + threads: CommentThread[], + account: AccountInfo +) { + if (!account.email) return []; + return threads.filter(t => + getMentionedUsers(t) + .map(v => v.email) + .includes(account.email) + ); +}
diff --git a/polygerrit-ui/app/utils/comment-util_test.ts b/polygerrit-ui/app/utils/comment-util_test.ts index 2cad710..4310396 100644 --- a/polygerrit-ui/app/utils/comment-util_test.ts +++ b/polygerrit-ui/app/utils/comment-util_test.ts
@@ -15,8 +15,13 @@ getContentInCommentRange, createUserFixSuggestion, PROVIDED_FIX_ID, + getMentionedThreads, } from './comment-util'; -import {createComment, createCommentThread} from '../test/test-data-generators'; +import { + createAccountWithEmail, + createComment, + createCommentThread, +} from '../test/test-data-generators'; import {CommentSide} from '../constants/constants'; import { PARENT, @@ -83,6 +88,43 @@ }); }); + test('getMentionedThreads', () => { + const account = createAccountWithEmail('abcd@def.com'); + const threads = [ + createCommentThread([ + { + ...createComment(), + message: 'random text with no emails', + }, + ]), + createCommentThread([ + { + ...createComment(), + message: '@abcd@def.com please take a look', + }, + { + ...createComment(), + message: '@abcd@def.com please take a look again at this', + }, + ]), + createCommentThread([ + { + ...createComment(), + message: '@abcd@def.com this is important', + }, + ]), + ]; + assert.deepEqual(getMentionedThreads(threads, account), [ + threads[1], + threads[2], + ]); + + assert.deepEqual( + getMentionedThreads(threads, createAccountWithEmail('xyz@def.com')), + [] + ); + }); + test('comments sorting', () => { const comments = [ {