The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/lib/server/functions/notifications/desktop.js

76 lines
2.2 KiB

import { metrics } from '../../../../metrics';
import { settings } from '../../../../settings';
import { Notifications } from '../../../../notifications';
import { roomCoordinator } from '../../../../../server/lib/rooms/roomCoordinator';
/**
* Send notification to user
*
* @param {string} userId The user to notify
* @param {object} user The sender
* @param {object} room The room send from
* @param {object} message The message object
* @param {number} duration Duration of notification
* @param {string} notificationMessage The message text to send on notification body
*/
export function notifyDesktopUser({ userId, user, message, room, duration, notificationMessage }) {
const { title, text } = roomCoordinator.getRoomDirectives(room.t)?.getNotificationDetails(room, user, notificationMessage);
metrics.notificationsSent.inc({ notification_type: 'desktop' });
Notifications.notifyUser(userId, 'notification', {
title,
text,
duration,
payload: {
_id: message._id,
rid: message.rid,
tmid: message.tmid,
sender: message.u,
type: room.t,
name: room.name,
message: {
msg: message.msg,
t: message.t,
},
},
});
}
export function shouldNotifyDesktop({
disableAllMessageNotifications,
status,
statusConnection,
desktopNotifications,
hasMentionToAll,
hasMentionToHere,
isHighlighted,
hasMentionToUser,
hasReplyToThread,
roomType,
isThread,
}) {
if (disableAllMessageNotifications && desktopNotifications == null && !isHighlighted && !hasMentionToUser && !hasReplyToThread) {
return false;
}
if (statusConnection === 'offline' || status === 'busy' || desktopNotifications === 'nothing') {
return false;
}
if (!desktopNotifications) {
if (settings.get('Accounts_Default_User_Preferences_desktopNotifications') === 'all' && (!isThread || hasReplyToThread)) {
return true;
}
if (settings.get('Accounts_Default_User_Preferences_desktopNotifications') === 'nothing') {
return false;
}
}
return (
(roomType === 'd' ||
(!disableAllMessageNotifications && (hasMentionToAll || hasMentionToHere)) ||
isHighlighted ||
desktopNotifications === 'all' ||
hasMentionToUser) &&
(!isThread || hasReplyToThread)
);
}