From eb10f92875729849db2aa32219c268e854b4f14d Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Sat, 25 Jun 2022 08:05:02 -0400 Subject: [PATCH] Fix recent mentions --- app/actions/remote/post.ts | 15 +++++---------- app/actions/remote/search.ts | 7 +++---- app/helpers/api/user.ts | 13 ++++++++----- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/app/actions/remote/post.ts b/app/actions/remote/post.ts index aa335be15..9c11cce7d 100644 --- a/app/actions/remote/post.ts +++ b/app/actions/remote/post.ts @@ -577,17 +577,12 @@ export const fetchPostAuthors = async (serverUrl: string, posts: Post[], fetchOn const usernamesToLoad = getNeededAtMentionedUsernames(existingUserNames, posts, excludeUsername); const userIdsToLoad = new Set(); - posts.forEach((p) => { - const userId = p.user_id; - - if (userId === currentUserId) { - return; + for (const p of posts) { + const {user_id} = p; + if (user_id !== currentUserId) { + userIdsToLoad.add(user_id); } - - if (!existingUserIds.has(userId)) { - userIdsToLoad.add(userId); - } - }); + } try { const promises: Array> = []; diff --git a/app/actions/remote/search.ts b/app/actions/remote/search.ts index 3aa4154dc..2f3d19d6b 100644 --- a/app/actions/remote/search.ts +++ b/app/actions/remote/search.ts @@ -45,16 +45,15 @@ export async function fetchRecentMentions(serverUrl: string): Promise> = []; const mentions: IdValue = { id: SYSTEM_IDENTIFIERS.RECENT_MENTIONS, value: JSON.stringify(results.order), }; - promises.push(operator.handleSystem({ + await operator.handleSystem({ systems: [mentions], - prepareRecordsOnly: true, - })); + prepareRecordsOnly: false, + }); return results; } catch (error) { diff --git a/app/helpers/api/user.ts b/app/helpers/api/user.ts index c51f63a88..890fa9ff9 100644 --- a/app/helpers/api/user.ts +++ b/app/helpers/api/user.ts @@ -11,23 +11,26 @@ export const getNeededAtMentionedUsernames = (usernames: Set, posts: Pos posts.forEach((p) => { let match; while ((match = pattern.exec(p.message)) !== null) { + const lowercaseMatch1 = match[1].toLowerCase(); + const lowercaseMatch2 = match[2].toLowerCase(); + // match[1] is the matched mention including trailing punctuation // match[2] is the matched mention without trailing punctuation - if (General.SPECIAL_MENTIONS.has(match[2])) { + if (General.SPECIAL_MENTIONS.has(lowercaseMatch2)) { continue; } - if (match[1] === excludeUsername || match[2] === excludeUsername) { + if (lowercaseMatch1 === excludeUsername || lowercaseMatch2 === excludeUsername) { continue; } - if (usernames.has(match[1]) || usernames.has(match[2])) { + if (usernames.has(lowercaseMatch1) || usernames.has(lowercaseMatch2)) { continue; } // If there's no trailing punctuation, this will only add 1 item to the set - usernamesToLoad.add(match[1]); - usernamesToLoad.add(match[2]); + usernamesToLoad.add(lowercaseMatch1); + usernamesToLoad.add(lowercaseMatch2); } });