Skip to content

Commit 3c5a961

Browse files
Merge pull request Expensify#76932 from marufsharifi/fix/notifications-not-delivered-after-online
Fix pending notifications not being received after going online
2 parents c0289c3 + 6c63985 commit 3c5a961

3 files changed

Lines changed: 30 additions & 18 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type {OnyxCollection} from 'react-native-onyx';
2+
import {showReportActionNotification} from '@libs/actions/Report';
3+
import ONYXKEYS from '@src/ONYXKEYS';
4+
import type {ReportAction} from '@src/types/onyx';
5+
import type {OnyxServerUpdate} from '@src/types/onyx/OnyxUpdatesFromServer';
6+
7+
export default function triggerNotifications(onyxUpdates: OnyxServerUpdate[]): void {
8+
for (const update of onyxUpdates) {
9+
if (!update.shouldNotify && !update.shouldShowPushNotification) {
10+
continue;
11+
}
12+
13+
const reportID = update.key.replace(ONYXKEYS.COLLECTION.REPORT_ACTIONS, '');
14+
const reportActions = Object.values((update.value as OnyxCollection<ReportAction>) ?? {});
15+
16+
for (const action of reportActions) {
17+
if (action) {
18+
showReportActionNotification(reportID, action);
19+
}
20+
}
21+
}
22+
}

src/libs/actions/OnyxUpdates.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import {Platform} from 'react-native';
12
import type {OnyxUpdate} from 'react-native-onyx';
23
import Onyx from 'react-native-onyx';
34
import type {Merge} from 'type-fest';
45
import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
6+
import {isMobile} from '@libs/Browser';
57
import Log from '@libs/Log';
8+
import triggerNotifications from '@libs/Notification/triggerNotifications';
69
import Performance from '@libs/Performance';
710
import PusherUtils from '@libs/PusherUtils';
811
import CONST from '@src/CONST';
@@ -53,6 +56,10 @@ function applyHTTPSOnyxUpdates(request: Request, response: Response, lastUpdateI
5356

5457
return onyxDataUpdatePromise
5558
.then(() => {
59+
// Trigger notifications only on successful responses.
60+
if (Platform.OS === 'web' && !isMobile() && response.jsonCode === 200 && response.onyxData?.length) {
61+
triggerNotifications(response.onyxData);
62+
}
5663
// Handle the request's success/failure data (client-side data)
5764
if (response.jsonCode === 200 && request.successData) {
5865
return updateHandler(request.successData);

src/libs/actions/User.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import Log from '@libs/Log';
3434
import Navigation from '@libs/Navigation/Navigation';
3535
import {isOffline} from '@libs/Network/NetworkStore';
3636
import * as SequentialQueue from '@libs/Network/SequentialQueue';
37+
import triggerNotifications from '@libs/Notification/triggerNotifications';
3738
import * as NumberUtils from '@libs/NumberUtils';
3839
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
3940
import Pusher from '@libs/Pusher';
@@ -57,7 +58,6 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject';
5758
import {reconnectApp} from './App';
5859
import applyOnyxUpdatesReliably from './applyOnyxUpdatesReliably';
5960
import {openOldDotLink} from './Link';
60-
import {showReportActionNotification} from './Report';
6161
import {resendValidateCode as sessionResendValidateCode} from './Session';
6262
import Timing from './Timing';
6363

@@ -660,23 +660,6 @@ function isBlockedFromConcierge(blockedFromConciergeNVP: OnyxEntry<BlockedFromCo
660660
return isBefore(new Date(), new Date(blockedFromConciergeNVP.expiresAt));
661661
}
662662

663-
function triggerNotifications(onyxUpdates: OnyxServerUpdate[]) {
664-
for (const update of onyxUpdates) {
665-
if (!update.shouldNotify && !update.shouldShowPushNotification) {
666-
continue;
667-
}
668-
669-
const reportID = update.key.replace(ONYXKEYS.COLLECTION.REPORT_ACTIONS, '');
670-
const reportActions = Object.values((update.value as OnyxCollection<ReportAction>) ?? {});
671-
672-
for (const action of reportActions) {
673-
if (action) {
674-
showReportActionNotification(reportID, action);
675-
}
676-
}
677-
}
678-
}
679-
680663
const isChannelMuted = (reportId: string) =>
681664
new Promise((resolve) => {
682665
const connection = Onyx.connect({

0 commit comments

Comments
 (0)