diff --git a/app/constants/push_notification.ts b/app/constants/push_notification.ts index fc918c066..37ed85d3b 100644 --- a/app/constants/push_notification.ts +++ b/app/constants/push_notification.ts @@ -11,6 +11,10 @@ export const NOTIFICATION_TYPE = { SESSION: 'session', }; +export const NOTIFICATION_SUB_TYPE = { + CALLS: 'calls', +}; + export default { CATEGORY, NOTIFICATION_TYPE, diff --git a/app/init/push_notifications.ts b/app/init/push_notifications.ts index 132332da1..f713d4f47 100644 --- a/app/init/push_notifications.ts +++ b/app/init/push_notifications.ts @@ -18,6 +18,7 @@ import {storeDeviceToken} from '@actions/app/global'; import {markChannelAsViewed} from '@actions/local/channel'; import {updateThread} from '@actions/local/thread'; import {backgroundNotification, openNotification} from '@actions/remote/notifications'; +import {isCallsStartedMessage} from '@calls/utils'; import {Device, Events, Navigation, PushNotification, Screens} from '@constants'; import DatabaseManager from '@database/manager'; import {DEFAULT_LOCALE, getLocalizedMessage, t} from '@i18n'; @@ -107,6 +108,11 @@ class PushNotifications { handleInAppNotification = async (serverUrl: string, notification: NotificationWithData) => { const {payload} = notification; + // Do not show overlay if this is a call-started message (the call_notification will alert the user) + if (isCallsStartedMessage(payload)) { + return; + } + const database = DatabaseManager.serverDatabases[serverUrl]?.database; if (database) { const isTabletDevice = await isTablet(); diff --git a/app/products/calls/utils.ts b/app/products/calls/utils.ts index 63ed92580..d7dabc34a 100644 --- a/app/products/calls/utils.ts +++ b/app/products/calls/utils.ts @@ -5,6 +5,7 @@ import {makeCallsBaseAndBadgeRGB, rgbToCSS} from '@mattermost/calls'; import {Alert} from 'react-native'; import {Calls, Post} from '@constants'; +import {NOTIFICATION_SUB_TYPE} from '@constants/push_notification'; import {isMinimumServerVersion} from '@utils/helpers'; import {displayUsername} from '@utils/user'; @@ -14,6 +15,8 @@ import type PostModel from '@typings/database/models/servers/post'; import type {IntlShape} from 'react-intl'; import type {RTCIceServer} from 'react-native-webrtc'; +const callsMessageRegex = /^\u200b.* is inviting you to a call$/; + export function sortParticipants(locale: string, teammateNameDisplay: string, participants?: Dictionary, presenterID?: string): CallParticipant[] { if (!participants) { return []; @@ -150,3 +153,13 @@ export function makeCallsTheme(theme: Theme): CallsTheme { return newTheme; } + +export function isCallsStartedMessage(payload?: NotificationData) { + if (payload?.sub_type === NOTIFICATION_SUB_TYPE.CALLS) { + return true; + } + + // MM-55506 - Remove once we can assume MM servers will be >= 9.3.0, mobile will be >= 2.11.0, + // calls will be >= 0.21.0, and push proxy will be >= 5.27.0 + return (payload?.message === 'You\'ve been invited to a call' || callsMessageRegex.test(payload?.message || '')); +} diff --git a/app/utils/notification/index.ts b/app/utils/notification/index.ts index 8460de9c9..81309510d 100644 --- a/app/utils/notification/index.ts +++ b/app/utils/notification/index.ts @@ -6,6 +6,7 @@ import {createIntl, type IntlShape} from 'react-intl'; import {Alert, DeviceEventEmitter} from 'react-native'; import {Events} from '@constants'; +import {NOTIFICATION_TYPE} from '@constants/push_notification'; import {DEFAULT_LOCALE, getTranslations} from '@i18n'; import PushNotifications from '@init/push_notifications'; import {popToRoot} from '@screens/navigation'; @@ -24,7 +25,7 @@ export const convertToNotificationData = (notification: Notification, tapped = t channel_name: payload.channel_name, identifier: payload.identifier || notification.identifier, from_webhook: payload.from_webhook, - message: ((payload.type === 'message') ? payload.message || notification.body : payload.body), + message: ((payload.type === NOTIFICATION_TYPE.MESSAGE) ? payload.message || notification.body : payload.body), override_icon_url: payload.override_icon_url, override_username: payload.override_username, post_id: payload.post_id, @@ -35,6 +36,7 @@ export const convertToNotificationData = (notification: Notification, tapped = t server_url: payload.server_url, team_id: payload.team_id, type: payload.type, + sub_type: payload.sub_type, use_user_icon: payload.use_user_icon, version: payload.version, isCRTEnabled: typeof payload.is_crt_enabled === 'string' ? payload.is_crt_enabled === 'true' : Boolean(payload.is_crt_enabled), diff --git a/types/global/push_notifications.d.ts b/types/global/push_notifications.d.ts index a8c5d5258..4b180ed8c 100644 --- a/types/global/push_notifications.d.ts +++ b/types/global/push_notifications.d.ts @@ -36,6 +36,7 @@ interface NotificationData { server_url?: string; team_id?: string; type: string; + sub_type?: string; use_user_icon?: string; userInfo?: NotificationUserInfo; version: string;