Skip to content

Commit

Permalink
Merge pull request #33386 from Expensify/arosiclair-disable-clear-not…
Browse files Browse the repository at this point in the history
…ifs-android

Disable clearReportNotifications on Android
  • Loading branch information
jasperhuangg authored Dec 21, 2023
2 parents 6797636 + f4ae144 commit 1a30d62
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 44 deletions.
36 changes: 0 additions & 36 deletions src/libs/Notification/PushNotification/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Airship, {EventType, PushPayload} from '@ua/react-native-airship';
import Onyx from 'react-native-onyx';
import Log from '@libs/Log';
import * as PushNotificationActions from '@userActions/PushNotification';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ForegroundNotifications from './ForegroundNotifications';
import NotificationType, {NotificationData} from './NotificationType';
Expand Down Expand Up @@ -190,40 +189,6 @@ const clearNotifications: ClearNotifications = () => {
Airship.push.clearNotifications();
};

const parseNotificationAndReportIDs = (pushPayload: PushPayload) => {
let payload = pushPayload.extras.payload;
if (typeof payload === 'string') {
payload = JSON.parse(payload);
}
const data = payload as NotificationData;
return {
notificationID: pushPayload.notificationId,
reportID: String(data.reportID),
};
};

const clearReportNotifications = (reportID: string) => {
Log.info('[PushNotification] clearing report notifications', false, {reportID});

Airship.push
.getActiveNotifications()
.then((pushPayloads) => {
const reportNotificationIDs = pushPayloads.reduce<string[]>((notificationIDs, pushPayload) => {
const notification = parseNotificationAndReportIDs(pushPayload);
if (notification.notificationID && notification.reportID === reportID) {
notificationIDs.push(notification.notificationID);
}
return notificationIDs;
}, []);

Log.info(`[PushNotification] found ${reportNotificationIDs.length} notifications to clear`, false, {reportID});
reportNotificationIDs.forEach((notificationID) => Airship.push.clearNotification(notificationID));
})
.catch((error) => {
Log.alert(`${CONST.ERROR.ENSURE_BUGBOT} [PushNotification] BrowserNotifications.clearReportNotifications threw an error. This should never happen.`, {reportID, error});
});
};

const PushNotification: PushNotificationType = {
init,
register,
Expand All @@ -232,7 +197,6 @@ const PushNotification: PushNotificationType = {
onSelected,
TYPE: NotificationType,
clearNotifications,
clearReportNotifications,
};

export default PushNotification;
1 change: 0 additions & 1 deletion src/libs/Notification/PushNotification/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const PushNotification: PushNotificationType = {
onSelected: () => {},
TYPE: NotificationType,
clearNotifications: () => {},
clearReportNotifications: () => {},
};

export default PushNotification;
2 changes: 0 additions & 2 deletions src/libs/Notification/PushNotification/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {ValueOf} from 'type-fest';
import ClearReportNotifications from '@libs/Notification/clearReportNotifications/types';
import NotificationType, {NotificationDataMap} from './NotificationType';

type Init = () => void;
Expand All @@ -17,7 +16,6 @@ type PushNotification = {
onSelected: OnSelected;
TYPE: typeof NotificationType;
clearNotifications: ClearNotifications;
clearReportNotifications: ClearReportNotifications;
};

export default PushNotification;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import ClearReportNotifications from './types';

/**
* This is a temporary fix for issues with our Notification Cache not being cleared in Android.
* More info here: https://github.com/Expensify/App/issues/33367#issuecomment-1865196381
*/
const clearReportNotifications: ClearReportNotifications = () => {};

export default clearReportNotifications;
41 changes: 41 additions & 0 deletions src/libs/Notification/clearReportNotifications/index.ios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Airship, {PushPayload} from '@ua/react-native-airship';
import Log from '@libs/Log';
import {NotificationData} from '@libs/Notification/PushNotification/NotificationType';
import CONST from '@src/CONST';
import ClearReportNotifications from './types';

const parseNotificationAndReportIDs = (pushPayload: PushPayload) => {
let payload = pushPayload.extras.payload;
if (typeof payload === 'string') {
payload = JSON.parse(payload);
}
const data = payload as NotificationData;
return {
notificationID: pushPayload.notificationId,
reportID: String(data.reportID),
};
};

const clearReportNotifications: ClearReportNotifications = (reportID: string) => {
Log.info('[PushNotification] clearing report notifications', false, {reportID});

Airship.push
.getActiveNotifications()
.then((pushPayloads) => {
const reportNotificationIDs = pushPayloads.reduce<string[]>((notificationIDs, pushPayload) => {
const notification = parseNotificationAndReportIDs(pushPayload);
if (notification.notificationID && notification.reportID === reportID) {
notificationIDs.push(notification.notificationID);
}
return notificationIDs;
}, []);

Log.info(`[PushNotification] found ${reportNotificationIDs.length} notifications to clear`, false, {reportID});
reportNotificationIDs.forEach((notificationID) => Airship.push.clearNotification(notificationID));
})
.catch((error) => {
Log.alert(`${CONST.ERROR.ENSURE_BUGBOT} [PushNotification] BrowserNotifications.clearReportNotifications threw an error. This should never happen.`, {reportID, error});
});
};

export default clearReportNotifications;

This file was deleted.

0 comments on commit 1a30d62

Please sign in to comment.