diff --git a/.changeset/brave-shrimps-marry.md b/.changeset/brave-shrimps-marry.md new file mode 100644 index 0000000000000..af5b0f2a8c938 --- /dev/null +++ b/.changeset/brave-shrimps-marry.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +Improved support for higlighted words in threads (rooms are now marked as unread and notifications are sent) diff --git a/apps/meteor/app/lib/server/functions/notifications/desktop.ts b/apps/meteor/app/lib/server/functions/notifications/desktop.ts index 2d06cc51f222d..a20ed6ba16774 100644 --- a/apps/meteor/app/lib/server/functions/notifications/desktop.ts +++ b/apps/meteor/app/lib/server/functions/notifications/desktop.ts @@ -105,6 +105,6 @@ export function shouldNotifyDesktop({ isHighlighted || desktopNotifications === 'all' || hasMentionToUser) && - (!isThread || hasReplyToThread) + (isHighlighted || !isThread || hasReplyToThread) ); } diff --git a/apps/meteor/app/lib/server/functions/notifications/email.js b/apps/meteor/app/lib/server/functions/notifications/email.js index b0953293ac736..dfc6a1716703a 100644 --- a/apps/meteor/app/lib/server/functions/notifications/email.js +++ b/apps/meteor/app/lib/server/functions/notifications/email.js @@ -224,6 +224,6 @@ export function shouldNotifyEmail({ emailNotifications === 'all' || hasMentionToUser || (!disableAllMessageNotifications && hasMentionToAll)) && - (!isThread || hasReplyToThread) + (isHighlighted || !isThread || hasReplyToThread) ); } diff --git a/apps/meteor/app/lib/server/functions/notifications/mobile.js b/apps/meteor/app/lib/server/functions/notifications/mobile.js index a0aa3fa240235..cf8b526a6abcd 100644 --- a/apps/meteor/app/lib/server/functions/notifications/mobile.js +++ b/apps/meteor/app/lib/server/functions/notifications/mobile.js @@ -115,6 +115,6 @@ export function shouldNotifyMobile({ isHighlighted || mobilePushNotifications === 'all' || hasMentionToUser) && - (!isThread || hasReplyToThread) + (isHighlighted || !isThread || hasReplyToThread) ); } diff --git a/apps/meteor/app/lib/server/lib/notifyUsersOnMessage.js b/apps/meteor/app/lib/server/lib/notifyUsersOnMessage.js index b55a272de558c..ccd06e886b9ff 100644 --- a/apps/meteor/app/lib/server/lib/notifyUsersOnMessage.js +++ b/apps/meteor/app/lib/server/lib/notifyUsersOnMessage.js @@ -73,7 +73,7 @@ const incUserMentions = async (rid, roomType, uids, unreadCount) => { await Subscriptions.incUserMentionsAndUnreadForRoomIdAndUserIds(rid, uids, 1, incUnread); }; -const getUserIdsFromHighlights = async (rid, message) => { +export const getUserIdsFromHighlights = async (rid, message) => { const highlightOptions = { projection: { 'userHighlights': 1, 'u._id': 1 } }; const subs = await Subscriptions.findByRoomWithUserHighlights(rid, highlightOptions).toArray(); diff --git a/apps/meteor/app/threads/server/functions.ts b/apps/meteor/app/threads/server/functions.ts index b146cb7d00414..30daef8b8b933 100644 --- a/apps/meteor/app/threads/server/functions.ts +++ b/apps/meteor/app/threads/server/functions.ts @@ -2,7 +2,7 @@ import type { IMessage } from '@rocket.chat/core-typings'; import { isEditedMessage } from '@rocket.chat/core-typings'; import { Messages, Subscriptions, ReadReceipts, NotificationQueue } from '@rocket.chat/models'; -import { getMentions } from '../../lib/server/lib/notifyUsersOnMessage'; +import { getMentions, getUserIdsFromHighlights } from '../../lib/server/lib/notifyUsersOnMessage'; export async function reply({ tmid }: { tmid?: string }, message: IMessage, parentMessage: IMessage, followers: string[]) { const { rid, ts, u } = message; @@ -19,7 +19,9 @@ export async function reply({ tmid }: { tmid?: string }, message: IMessage, pare ...(Array.isArray(parentMessage.replies) && parentMessage.replies.length ? [u._id] : [parentMessage.u._id, u._id]), ]), ]; + const highlightedUserIds = new Set(); + (await getUserIdsFromHighlights(rid, message)).forEach((uid) => highlightedUserIds.add(uid)); await Messages.updateRepliesByThreadId(tmid, addToReplies, ts); await ReadReceipts.setAsThreadById(tmid); @@ -35,9 +37,16 @@ export async function reply({ tmid }: { tmid?: string }, message: IMessage, pare await Subscriptions.addUnreadThreadByRoomIdAndUserIds(rid, repliesFiltered, tmid, {}); } - for await (const userId of mentionIds) { + const mentionedUsers = new Set([...mentionIds, ...highlightedUserIds]); + for await (const userId of mentionedUsers) { await Subscriptions.addUnreadThreadByRoomIdAndUserIds(rid, [userId], tmid, { userMention: true }); } + + const highlightIds = Array.from(highlightedUserIds); + if (highlightIds.length) { + await Subscriptions.setAlertForRoomIdAndUserIds(rid, highlightIds); + await Subscriptions.setOpenForRoomIdAndUserIds(rid, highlightIds); + } } export async function follow({ tmid, uid }: { tmid: string; uid: string }) {