From c1d28608a75f52b4aa6c0209281477378dfda021 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Wed, 28 Feb 2024 15:35:36 -0300 Subject: [PATCH] fix: check notification payload --- app/lib/notifications/index.ts | 46 ++++++++++--------- .../backgroundNotificationHandler.ts | 16 ++++--- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/app/lib/notifications/index.ts b/app/lib/notifications/index.ts index edc6e0440a..2a86222edf 100644 --- a/app/lib/notifications/index.ts +++ b/app/lib/notifications/index.ts @@ -18,35 +18,37 @@ interface IEjson { export const onNotification = (push: INotification): void => { const identifier = String(push?.payload?.action?.identifier); if (identifier === 'ACCEPT_ACTION' || identifier === 'DECLINE_ACTION') { - if (push.payload) { - const notification = EJSON.parse(push.payload.ejson); + if (push?.payload && push?.payload?.ejson) { + const notification = EJSON.parse(push?.payload?.ejson); store.dispatch(deepLinkingClickCallPush({ ...notification, event: identifier === 'ACCEPT_ACTION' ? 'accept' : 'decline' })); return; } } - if (push.payload) { + if (push?.payload) { try { - const notification = push.payload; - const { rid, name, sender, type, host, messageId }: IEjson = EJSON.parse(notification.ejson); + const notification = push?.payload; + if (notification.ejson) { + const { rid, name, sender, type, host, messageId }: IEjson = EJSON.parse(notification.ejson); - const types: Record = { - c: 'channel', - d: 'direct', - p: 'group', - l: 'channels' - }; - let roomName = type === SubscriptionType.DIRECT ? sender.username : name; - if (type === SubscriptionType.OMNICHANNEL) { - roomName = sender.name; - } + const types: Record = { + c: 'channel', + d: 'direct', + p: 'group', + l: 'channels' + }; + let roomName = type === SubscriptionType.DIRECT ? sender.username : name; + if (type === SubscriptionType.OMNICHANNEL) { + roomName = sender.name; + } - const params = { - host, - rid, - messageId, - path: `${types[type]}/${roomName}` - }; - store.dispatch(deepLinkingOpen(params)); + const params = { + host, + rid, + messageId, + path: `${types[type]}/${roomName}` + }; + store.dispatch(deepLinkingOpen(params)); + } } catch (e) { console.warn(e); } diff --git a/app/lib/notifications/videoConf/backgroundNotificationHandler.ts b/app/lib/notifications/videoConf/backgroundNotificationHandler.ts index 6d685c2f97..ab98808b34 100644 --- a/app/lib/notifications/videoConf/backgroundNotificationHandler.ts +++ b/app/lib/notifications/videoConf/backgroundNotificationHandler.ts @@ -105,13 +105,15 @@ const displayVideoConferenceNotification = async (notification: NotificationData const setBackgroundNotificationHandler = () => { createChannel(); messaging().setBackgroundMessageHandler(async message => { - const notification: NotificationData = ejson.parse(message?.data?.ejson as string); - if (notification?.notificationType === VIDEO_CONF_TYPE) { - if (notification.status === 0) { - await displayVideoConferenceNotification(notification); - } else if (notification.status === 4) { - const id = `${notification.rid}${notification.caller?._id}`.replace(/[^A-Za-z0-9]/g, ''); - await notifee.cancelNotification(id); + if (message?.data?.ejson) { + const notification: NotificationData = ejson.parse(message?.data?.ejson as string); + if (notification?.notificationType === VIDEO_CONF_TYPE) { + if (notification.status === 0) { + await displayVideoConferenceNotification(notification); + } else if (notification.status === 4) { + const id = `${notification.rid}${notification.caller?._id}`.replace(/[^A-Za-z0-9]/g, ''); + await notifee.cancelNotification(id); + } } }