# UNDF: UNDF-2026-000000263 --- a/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.ts +++ b/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.ts @@ -73,7 +73,8 @@ export const sendNotification = async ({ if (subscription.u._id === sender._id) { return; } - const hasMentionToUser = mentionIds.includes(subscription.u._id); + const hasMentionToUser = mentionIdSet.has(subscription.u._id); // mute group notifications (@here and @all) if not directly mentioned as well @@ -57,7 +57,8 @@ export const sendNotification = async ({ subscription, sender, hasReplyToThread, hasMentionToAll, hasMentionToHere, message, notificationMessage, room, - mentionIds, + mentionIdSet, disableAllMessageNotifications, }: { subscription: SubscriptionAggregation; sender: Pick; hasReplyToThread: boolean; hasMentionToAll: boolean; hasMentionToHere: boolean; message: AtLeast; notificationMessage: string; room: IRoom; - mentionIds: string[]; + mentionIdSet: Set; disableAllMessageNotifications: boolean; @@ -360,13 +360,15 @@ export async function sendMessageNotifications(message: IMessage, room: IRoom, const subscriptions = await Subscriptions.col.aggregate([{ $match: query }, lookup, filter, project]).toArray(); + const mentionIdSet = new Set(mentionIds); + const usersInThreadSet = new Set(usersInThread ?? []); + subscriptions.forEach( (subscription) => void sendNotification({ subscription, sender, hasMentionToAll, hasMentionToHere, message, notificationMessage, room, - mentionIds, + mentionIdSet, disableAllMessageNotifications, - hasReplyToThread: usersInThread?.includes(subscription.u._id), + hasReplyToThread: usersInThreadSet.has(subscription.u._id), }), );