MM-52888 Always load users mentioned in message attachments (#7361)

This commit is contained in:
Harrison Healey
2023-05-25 13:47:09 -04:00
committed by GitHub
parent 9b2c68985a
commit aa54d72a01

View File

@@ -7,9 +7,13 @@ import {MENTIONS_REGEX} from '@constants/autocomplete';
export const getNeededAtMentionedUsernames = (usernames: Set<string>, posts: Post[], excludeUsername?: string) => {
const usernamesToLoad = new Set<string>();
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<string>, 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;
};