Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/flat-fishes-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fix notifications specially for DMs when preference is set to mentions.
4 changes: 2 additions & 2 deletions apps/meteor/app/lib/server/functions/notifications/desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function shouldNotifyDesktop({
disableAllMessageNotifications: boolean;
status: string;
statusConnection: string;
desktopNotifications: string;
desktopNotifications: string | undefined;
hasMentionToAll: boolean;
hasMentionToHere: boolean;
isHighlighted: boolean;
Expand All @@ -90,7 +90,7 @@ export function shouldNotifyDesktop({
roomType: string;
isThread: boolean;
}): boolean {
if (disableAllMessageNotifications && desktopNotifications == null && !isHighlighted && !hasMentionToUser && !hasReplyToThread) {
if (disableAllMessageNotifications && !desktopNotifications && !isHighlighted && !hasMentionToUser && !hasReplyToThread) {
return false;
}

Expand Down
27 changes: 13 additions & 14 deletions apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { Subscriptions, Users } from '@rocket.chat/models';
import emojione from 'emojione';
import moment from 'moment';
import type { Filter, RootFilterOperators } from 'mongodb';
import type { RootFilterOperators } from 'mongodb';

import { callbacks } from '../../../../lib/callbacks';
import { roomCoordinator } from '../../../../server/lib/rooms/roomCoordinator';
Expand Down Expand Up @@ -117,7 +117,7 @@ export const sendNotification = async ({
disableAllMessageNotifications,
status: receiver.status ?? 'offline',
statusConnection: receiver.statusConnection ?? 'offline',
desktopNotifications: desktopNotifications ?? 'default',
desktopNotifications,
hasMentionToAll,
hasMentionToHere,
isHighlighted,
Expand Down Expand Up @@ -304,33 +304,32 @@ export async function sendMessageNotifications(message: IMessage, room: IRoom, u
} as const;

(['desktop', 'mobile', 'email'] as const).forEach((kind) => {
const notificationField = `${kind === 'mobile' ? 'mobilePush' : kind}Notifications`;
const notificationField = kind === 'mobile' ? 'mobilePush' : `${kind}Notifications`;

const filter: Filter<ISubscription> = { [notificationField]: 'all' };
query.$or.push({
[notificationField]: 'all',
...(disableAllMessageNotifications ? { [`${kind}PrefOrigin`]: { $ne: 'user' } } : {}),
});

if (disableAllMessageNotifications) {
filter[`${kind}PrefOrigin`] = { $ne: 'user' };
return;
}

query.$or.push(filter);

if (mentionIdsWithoutGroups.length > 0) {
if (room.t === 'd') {
query.$or.push({
[notificationField]: 'mentions',
'u._id': { $in: mentionIdsWithoutGroups },
});
} else if (!disableAllMessageNotifications && (hasMentionToAll || hasMentionToHere)) {
} else if (mentionIdsWithoutGroups.length > 0) {
query.$or.push({
[notificationField]: 'mentions',
'u._id': { $in: mentionIdsWithoutGroups },
});
}

const serverField = kind === 'email' ? 'emailNotificationMode' : `${kind}Notifications`;
const serverPreference = settings.get(`Accounts_Default_User_Preferences_${serverField}`);
if (
(room.t === 'd' && serverPreference !== 'nothing') ||
(!disableAllMessageNotifications && (serverPreference === 'all' || hasMentionToAll || hasMentionToHere))
) {

if (serverPreference === 'all' || hasMentionToAll || hasMentionToHere || room.t === 'd') {
query.$or.push({
[notificationField]: { $exists: false },
});
Expand Down