Skip to content

Commit

Permalink
fix: check notification payload
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlsilva committed Feb 28, 2024
1 parent 9a1f782 commit c1d2860
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
46 changes: 24 additions & 22 deletions app/lib/notifications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = {
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<string, string> = {
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);
}
Expand Down
16 changes: 9 additions & 7 deletions app/lib/notifications/videoConf/backgroundNotificationHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit c1d2860

Please sign in to comment.