diff --git a/.changeset/spotty-suns-grin.md b/.changeset/spotty-suns-grin.md new file mode 100644 index 00000000000..8045ebbd1b4 --- /dev/null +++ b/.changeset/spotty-suns-grin.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Improved the experience of receiving conference calls on the mobile app by disabling the push notification for the "new call" message if a push is already being sent to trigger the phone's ringing tone. diff --git a/apps/meteor/app/lib/server/functions/notifications/mobile.js b/apps/meteor/app/lib/server/functions/notifications/mobile.js index b4139bea6f1..a0aa3fa2402 100644 --- a/apps/meteor/app/lib/server/functions/notifications/mobile.js +++ b/apps/meteor/app/lib/server/functions/notifications/mobile.js @@ -1,6 +1,7 @@ import { Subscriptions } from '@rocket.chat/models'; import { i18n } from '../../../../../server/lib/i18n'; +import { isRoomCompatibleWithVideoConfRinging } from '../../../../../server/lib/isRoomCompatibleWithVideoConfRinging'; import { roomCoordinator } from '../../../../../server/lib/rooms/roomCoordinator'; import { settings } from '../../../../settings/server'; @@ -73,6 +74,9 @@ export function shouldNotifyMobile({ hasReplyToThread, roomType, isThread, + isVideoConf, + userPreferences, + roomUids, }) { if (settings.get('Push_enable') !== true) { return false; @@ -86,6 +90,16 @@ export function shouldNotifyMobile({ 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; diff --git a/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js b/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js index ce262e4e675..4ed882cfe87 100644 --- a/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js +++ b/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js @@ -48,12 +48,13 @@ export const sendNotification = async ({ subscription.receiver = [ await Users.findOneById(subscription.u._id, { projection: { - active: 1, - emails: 1, - language: 1, - status: 1, - statusConnection: 1, - username: 1, + 'active': 1, + 'emails': 1, + 'language': 1, + 'status': 1, + 'statusConnection': 1, + 'username': 1, + 'settings.preferences.enableMobileRinging': 1, }, }), ]; @@ -68,6 +69,7 @@ export const sendNotification = async ({ } const isThread = !!message.tmid && !message.tshow; + const isVideoConf = message.t === 'videoconf'; notificationMessage = await parseMessageTextPerUser(notificationMessage, message, receiver); @@ -112,6 +114,9 @@ export const sendNotification = async ({ hasReplyToThread, roomType, isThread, + isVideoConf, + userPreferences: receiver.settings?.preferences, + roomUids: room.uids, }) ) { queueItems.push({ @@ -189,6 +194,7 @@ const project = { 'receiver.status': 1, 'receiver.statusConnection': 1, 'receiver.username': 1, + 'receiver.settings.preferences.enableMobileRinging': 1, }, }; diff --git a/apps/meteor/server/lib/isRoomCompatibleWithVideoConfRinging.ts b/apps/meteor/server/lib/isRoomCompatibleWithVideoConfRinging.ts new file mode 100644 index 00000000000..3bd4f814b8d --- /dev/null +++ b/apps/meteor/server/lib/isRoomCompatibleWithVideoConfRinging.ts @@ -0,0 +1,4 @@ +import type { IRoom } from '@rocket.chat/core-typings'; + +export const isRoomCompatibleWithVideoConfRinging = (roomType: IRoom['t'], roomUids: IRoom['uids']): boolean => + Boolean(roomType === 'd' && roomUids && roomUids.length <= 2); diff --git a/apps/meteor/server/services/video-conference/service.ts b/apps/meteor/server/services/video-conference/service.ts index dd58d4b293f..f032606c2d8 100644 --- a/apps/meteor/server/services/video-conference/service.ts +++ b/apps/meteor/server/services/video-conference/service.ts @@ -47,6 +47,7 @@ import { callbacks } from '../../../lib/callbacks'; import { availabilityErrors } from '../../../lib/videoConference/constants'; import { readSecondaryPreferred } from '../../database/readSecondaryPreferred'; import { i18n } from '../../lib/i18n'; +import { isRoomCompatibleWithVideoConfRinging } from '../../lib/isRoomCompatibleWithVideoConfRinging'; import { videoConfProviders } from '../../lib/videoConfProviders'; import { videoConfTypes } from '../../lib/videoConfTypes'; @@ -74,7 +75,7 @@ export class VideoConfService extends ServiceClassInternal implements IVideoConf } if (type === 'direct') { - if (room.t !== 'd' || !room.uids || room.uids.length > 2) { + if (!isRoomCompatibleWithVideoConfRinging(room.t, room.uids)) { throw new Error('type-and-room-not-compatible'); }