Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
121 lines
3.5 KiB
JavaScript
121 lines
3.5 KiB
JavaScript
import { Subscriptions } from '@rocket.chat/models';
|
|
|
|
import { settings } from '../../../settings';
|
|
import { i18n } from '../../i18n';
|
|
import { isRoomCompatibleWithVideoConfRinging } from '../../isRoomCompatibleWithVideoConfRinging';
|
|
import { roomCoordinator } from '../../rooms/roomCoordinator';
|
|
|
|
const CATEGORY_MESSAGE = 'MESSAGE';
|
|
const CATEGORY_MESSAGE_NOREPLY = 'MESSAGE_NOREPLY';
|
|
|
|
function enableNotificationReplyButton(room, username) {
|
|
// Some users may have permission to send messages even on readonly rooms, but we're ok with false negatives here in exchange of better perfomance
|
|
if (room.ro === true) {
|
|
return false;
|
|
}
|
|
|
|
if (!room.muted) {
|
|
return true;
|
|
}
|
|
|
|
return !room.muted.includes(username);
|
|
}
|
|
|
|
export async function getPushData({
|
|
room,
|
|
message,
|
|
userId,
|
|
senderUsername,
|
|
senderName,
|
|
notificationMessage,
|
|
receiver,
|
|
shouldOmitMessage = true,
|
|
}) {
|
|
const username = settings.get('Push_show_username_room') ? (settings.get('UI_Use_Real_Name') && senderName) || senderUsername : '';
|
|
|
|
const lng = receiver.language || settings.get('Language') || 'en';
|
|
|
|
let messageText;
|
|
if (shouldOmitMessage && settings.get('Push_request_content_from_server')) {
|
|
messageText = i18n.t('You_have_a_new_message', { lng });
|
|
} else if (!settings.get('Push_show_message')) {
|
|
messageText = i18n.t('You_have_a_new_message', { lng });
|
|
} else {
|
|
messageText = notificationMessage;
|
|
}
|
|
|
|
return {
|
|
payload: {
|
|
sender: message.u,
|
|
senderName: username,
|
|
type: room.t,
|
|
name: settings.get('Push_show_username_room') ? room.name : '',
|
|
messageType: message.t,
|
|
tmid: message.tmid,
|
|
...(message.t === 'e2e' && { msg: message.msg, content: message.content }),
|
|
},
|
|
roomName:
|
|
settings.get('Push_show_username_room') && roomCoordinator.getRoomDirectives(room.t).isGroupChat(room)
|
|
? `#${await roomCoordinator.getRoomName(room.t, room, userId)}`
|
|
: '',
|
|
username,
|
|
message: messageText,
|
|
badge: await Subscriptions.getBadgeCount(userId),
|
|
category: enableNotificationReplyButton(room, receiver.username) ? CATEGORY_MESSAGE : CATEGORY_MESSAGE_NOREPLY,
|
|
};
|
|
}
|
|
|
|
export function shouldNotifyMobile({
|
|
disableAllMessageNotifications,
|
|
mobilePushNotifications,
|
|
hasMentionToAll,
|
|
isHighlighted,
|
|
hasMentionToUser,
|
|
hasReplyToThread,
|
|
roomType,
|
|
isThread,
|
|
isVideoConf,
|
|
userPreferences,
|
|
roomUids,
|
|
}) {
|
|
if (settings.get('Push_enable') !== true) {
|
|
return false;
|
|
}
|
|
|
|
if (disableAllMessageNotifications && mobilePushNotifications == null && !isHighlighted && !hasMentionToUser && !hasReplyToThread) {
|
|
return false;
|
|
}
|
|
|
|
if (mobilePushNotifications === 'nothing') {
|
|
return false;
|
|
}
|
|
|
|
// If the user is going to receive a ringing push notification, do not send another push for the message generated by that videoconference
|
|
if (
|
|
isVideoConf &&
|
|
settings.get('VideoConf_Mobile_Ringing') &&
|
|
isRoomCompatibleWithVideoConfRinging(roomType, roomUids) &&
|
|
(userPreferences?.enableMobileRinging ?? settings.get(`Accounts_Default_User_Preferences_enableMobileRinging`))
|
|
) {
|
|
return false;
|
|
}
|
|
|
|
if (!mobilePushNotifications) {
|
|
if (settings.get('Accounts_Default_User_Preferences_pushNotifications') === 'all' && (!isThread || hasReplyToThread)) {
|
|
return true;
|
|
}
|
|
if (settings.get('Accounts_Default_User_Preferences_pushNotifications') === 'nothing') {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return (
|
|
(roomType === 'd' ||
|
|
(!disableAllMessageNotifications && hasMentionToAll) ||
|
|
isHighlighted ||
|
|
mobilePushNotifications === 'all' ||
|
|
hasMentionToUser) &&
|
|
(isHighlighted || !isThread || hasReplyToThread)
|
|
);
|
|
}
|