diff --git a/lib/shared/messages/text-message-spec.js b/lib/shared/messages/text-message-spec.js --- a/lib/shared/messages/text-message-spec.js +++ b/lib/shared/messages/text-message-spec.js @@ -38,7 +38,10 @@ stripSpoilersFromNotifications, stripSpoilersFromMarkdownAST, } from '../markdown.js'; -import { threadIsGroupChat, extractMentionedMembers } from '../thread-utils.js'; +import { + threadIsGroupChat, + extractNewMentionedParentMembers, +} from '../thread-utils.js'; /** * most of the markdown leaves contain `content` field @@ -221,28 +224,20 @@ } invariant(parentThreadInfo, 'all sidebars should have a parent thread'); - const mentionedMembersOfParent = extractMentionedMembers( + const mentionedNewMembers = extractNewMentionedParentMembers( messageInfo.text, + threadInfo, parentThreadInfo, ); - if (mentionedMembersOfParent.size === 0) { - return; - } - - for (const member of threadInfo.members) { - if (member.role) { - mentionedMembersOfParent.delete(member.id); - } - } - const mentionedToAdd = [...mentionedMembersOfParent.keys()]; - if (mentionedToAdd.length === 0) { + if (mentionedNewMembers.length === 0) { return; } + const newMemberIDs = mentionedNewMembers.map(({ id }) => id); const addMembersPromise = callChangeThreadSettings({ threadID: threadInfo.id, - changes: { newMemberIDs: mentionedToAdd }, + changes: { newMemberIDs }, }); dispatchActionPromise(changeThreadSettingsActionTypes, addMembersPromise); diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js --- a/lib/shared/thread-utils.js +++ b/lib/shared/thread-utils.js @@ -474,6 +474,25 @@ return mentionedMembers; } +// When a member of the parent is mentioned in a sidebar, +// they will be automatically added to that sidebar +function extractNewMentionedParentMembers( + messageText: string, + threadInfo: ThreadInfo, + parentThreadInfo: ThreadInfo, +): AccountUserInfo[] { + const mentionedMembersOfParent = extractMentionedMembers( + messageText, + parentThreadInfo, + ); + for (const member of threadInfo.members) { + if (member.role) { + mentionedMembersOfParent.delete(member.id); + } + } + return [...mentionedMembersOfParent.values()]; +} + type SharedCreatePendingSidebarInput = { +sourceMessageInfo: ComposableMessageInfo | RobotextMessageInfo, +parentThreadInfo: ThreadInfo, @@ -1549,7 +1568,7 @@ parsePendingThreadID, createPendingThread, createUnresolvedPendingSidebar, - extractMentionedMembers, + extractNewMentionedParentMembers, createPendingSidebar, pendingThreadType, createRealThreadFromPendingThread,