fix: mobile users receives two push notifications when a direct call is started (#31164)

pull/31202/head
Pierre Lehnen 2 years ago committed by Guilherme Gazzo
parent 899031337c
commit 4e49fcc7d9
  1. 5
      .changeset/spotty-suns-grin.md
  2. 14
      apps/meteor/app/lib/server/functions/notifications/mobile.js
  3. 18
      apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js
  4. 4
      apps/meteor/server/lib/isRoomCompatibleWithVideoConfRinging.ts
  5. 3
      apps/meteor/server/services/video-conference/service.ts

@ -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.

@ -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;

@ -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,
},
};

@ -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);

@ -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');
}

Loading…
Cancel
Save