Fix recent mentions

This commit is contained in:
Elias Nahum 2022-06-25 08:05:02 -04:00
parent d2e2cf3ec1
commit eb10f92875
No known key found for this signature in database
GPG key ID: E038DB71E0B61702
3 changed files with 16 additions and 19 deletions

View file

@ -577,17 +577,12 @@ export const fetchPostAuthors = async (serverUrl: string, posts: Post[], fetchOn
const usernamesToLoad = getNeededAtMentionedUsernames(existingUserNames, posts, excludeUsername);
const userIdsToLoad = new Set<string>();
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<Promise<UserProfile[]>> = [];

View file

@ -45,16 +45,15 @@ export async function fetchRecentMentions(serverUrl: string): Promise<PostSearch
throw results.error;
}
const promises: Array<Promise<Model[]>> = [];
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) {

View file

@ -11,23 +11,26 @@ export const getNeededAtMentionedUsernames = (usernames: Set<string>, 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);
}
});