diff --git a/app/helpers/api/user.ts b/app/helpers/api/user.ts index 79bd792dc9..f0576f5841 100644 --- a/app/helpers/api/user.ts +++ b/app/helpers/api/user.ts @@ -7,9 +7,13 @@ import {MENTIONS_REGEX} from '@constants/autocomplete'; export const getNeededAtMentionedUsernames = (usernames: Set, posts: Post[], excludeUsername?: string) => { const usernamesToLoad = new Set(); - posts.forEach((p) => { + const findNeededUsernames = (text?: string) => { + if (!text || !text.includes('@')) { + return; + } + let match; - while ((match = MENTIONS_REGEX.exec(p.message)) !== null) { + while ((match = MENTIONS_REGEX.exec(text)) !== null) { const lowercaseMatch = match[1].toLowerCase(); if (General.SPECIAL_MENTIONS.has(lowercaseMatch)) { @@ -26,7 +30,19 @@ export const getNeededAtMentionedUsernames = (usernames: Set, posts: Pos usernamesToLoad.add(lowercaseMatch); } - }); + }; + + for (const post of posts) { + // These correspond to the fields searched by getMentionsEnabledFields on the server + findNeededUsernames(post.message); + + if (post.props?.attachments) { + for (const attachment of post.props.attachments) { + findNeededUsernames(attachment.pretext); + findNeededUsernames(attachment.text); + } + } + } return usernamesToLoad; };