Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ export default class Root extends React.Component<{}, IState> {
if ('configured' in notification) {
return;
}
onNotification(notification);
const result = onNotification(notification);
if (result?.catch) {
result.catch(e => console.warn('app/index.tsx: onNotification error', e));
}
return;
}

Expand Down
16 changes: 14 additions & 2 deletions app/lib/notifications/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import EJSON from 'ejson';
import { Platform } from 'react-native';

import { isPushVideoConfAlreadyProcessed } from './videoConf/deduplication';
import { appInit } from '../../actions/app';
import { deepLinkingClickCallPush, deepLinkingOpen } from '../../actions/deepLinking';
import { type INotification, SubscriptionType } from '../../definitions';
Expand All @@ -16,14 +17,18 @@ interface IEjson {
messageId: string;
}

export const onNotification = (push: INotification): void => {
export const onNotification = async (push: INotification): Promise<void> => {
const identifier = String(push?.payload?.action?.identifier);

// Handle video conf notification actions (Accept/Decline buttons)
if (identifier === 'ACCEPT_ACTION' || identifier === 'DECLINE_ACTION') {
if (push?.payload?.ejson) {
try {
const notification = EJSON.parse(push.payload.ejson);
const currentId = push.identifier || push.payload?.notId;
if (await isPushVideoConfAlreadyProcessed(currentId)) {
return;
}
store.dispatch(
deepLinkingClickCallPush({ ...notification, event: identifier === 'ACCEPT_ACTION' ? 'accept' : 'decline' })
);
Expand All @@ -40,6 +45,10 @@ export const onNotification = (push: INotification): void => {

// Handle video conf notification tap (default action) - treat as accept
if (notification?.notificationType === 'videoconf') {
const currentId = push.identifier || push.payload?.notId;
if (await isPushVideoConfAlreadyProcessed(currentId)) {
return;
}
store.dispatch(deepLinkingClickCallPush({ ...notification, event: 'accept' }));
return;
}
Expand Down Expand Up @@ -122,7 +131,10 @@ export const checkPendingNotification = async (): Promise<void> => {
},
identifier: notificationData.notId || ''
};
onNotification(notification);
const result = onNotification(notification);
if (result?.catch) {
result.catch(e => console.warn('[notifications/index.ts] onNotification error:', e));
}
} catch (e) {
console.warn('[notifications/index.ts] Failed to parse pending notification:', e);
}
Expand Down
14 changes: 11 additions & 3 deletions app/lib/notifications/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ const registerForPushNotifications = async (): Promise<string | null> => {
}
};

export const pushNotificationConfigure = (onNotification: (notification: INotification) => void): Promise<any> => {
export const pushNotificationConfigure = (
onNotification: (notification: INotification) => Promise<void> | void
): Promise<any> => {
if (configured) {
return Promise.resolve({ configured: true });
}
Expand Down Expand Up @@ -207,10 +209,16 @@ export const pushNotificationConfigure = (onNotification: (notification: INotifi
if (isIOS) {
const { background } = reduxStore.getState().app;
if (background) {
onNotification(notification);
const result = onNotification(notification);
if (result?.catch) {
result.catch((e: any) => console.warn('[push.ts] Notification handler error:', e));
}
}
} else {
onNotification(notification);
const result = onNotification(notification);
if (result?.catch) {
result.catch((e: any) => console.warn('[push.ts] Notification handler error:', e));
}
}
});

Expand Down
31 changes: 31 additions & 0 deletions app/lib/notifications/videoConf/deduplication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import AsyncStorage from '@react-native-async-storage/async-storage';

const processingIds = new Set<string>();

export const isPushVideoConfAlreadyProcessed = async (notificationId?: string | null): Promise<boolean> => {
if (!notificationId) {
return false; // Can't dedup without an ID
}

// 1. Synchronously check and lock in-memory to prevent TOCTOU race condition
if (processingIds.has(notificationId)) {
return true;
}
processingIds.add(notificationId);

// 2. Check persistent storage (for cold boot scenarios)
try {
const lastId = await AsyncStorage.getItem('lastProcessedVideoConfNotificationId');
if (lastId === notificationId) {
return true;
}

// 3. Persist new ID
await AsyncStorage.setItem('lastProcessedVideoConfNotificationId', notificationId);
} catch (e) {
// Ignore storage errors, we still have the in-memory lock
console.warn('Error reading/writing video conf dedup state', e);
}

return false;
};
5 changes: 5 additions & 0 deletions app/lib/notifications/videoConf/getInitialNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Notifications from 'expo-notifications';
import EJSON from 'ejson';
import { DeviceEventEmitter, Platform } from 'react-native';

import { isPushVideoConfAlreadyProcessed } from './deduplication';
import { deepLinkingClickCallPush } from '../../../actions/deepLinking';
import { store } from '../../store/auxStore';
import NativeVideoConfModule from '../../native/NativeVideoConfAndroid';
Expand Down Expand Up @@ -66,6 +67,10 @@ export const getInitialNotification = async (): Promise<boolean> => {
if (payload.ejson) {
const ejsonData = EJSON.parse(payload.ejson);
if (ejsonData?.notificationType === 'videoconf') {
const notificationId = notification.request.identifier;
if (await isPushVideoConfAlreadyProcessed(notificationId)) {
return false;
}
// Accept/Decline actions or default tap (treat as accept)
let event = 'accept';
if (actionIdentifier === 'DECLINE_ACTION') {
Expand Down
8 changes: 8 additions & 0 deletions app/sagas/deepLinking.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { all, call, delay, put, select, take, takeLatest } from 'redux-saga/effects';

import { isPushVideoConfAlreadyProcessed } from '../lib/notifications/videoConf/deduplication';

import { shareSetParams } from '../actions/share';
import * as types from '../actions/actionsTypes';
import { appInit, appStart, appReady } from '../actions/app';
Expand Down Expand Up @@ -245,11 +247,17 @@ const handleNavigateCallRoom = function* handleNavigateCallRoom({ params }) {

const handleClickCallPush = function* handleClickCallPush({ params }) {
let { host } = params;
const notId = params.notId || params.identifier || params.payload?.notId || params.push?.identifier || params.push?.payload?.notId;

if (!host) {
return;
}

const isProcessed = yield call(isPushVideoConfAlreadyProcessed, notId);
if (isProcessed) {
return;
}

if (host.slice(-1) === '/') {
host = host.slice(0, host.length - 1);
}
Expand Down