diff --git a/src/libs/Notification/PushNotification/index.native.ts b/src/libs/Notification/PushNotification/index.native.ts index d48d56f71993..7b2571eea368 100644 --- a/src/libs/Notification/PushNotification/index.native.ts +++ b/src/libs/Notification/PushNotification/index.native.ts @@ -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'; @@ -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((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, @@ -232,7 +197,6 @@ const PushNotification: PushNotificationType = { onSelected, TYPE: NotificationType, clearNotifications, - clearReportNotifications, }; export default PushNotification; diff --git a/src/libs/Notification/PushNotification/index.ts b/src/libs/Notification/PushNotification/index.ts index 925574b8976f..1e5499d1fe7d 100644 --- a/src/libs/Notification/PushNotification/index.ts +++ b/src/libs/Notification/PushNotification/index.ts @@ -10,7 +10,6 @@ const PushNotification: PushNotificationType = { onSelected: () => {}, TYPE: NotificationType, clearNotifications: () => {}, - clearReportNotifications: () => {}, }; export default PushNotification; diff --git a/src/libs/Notification/PushNotification/types.ts b/src/libs/Notification/PushNotification/types.ts index e39f21e0cb92..f72ee1af887a 100644 --- a/src/libs/Notification/PushNotification/types.ts +++ b/src/libs/Notification/PushNotification/types.ts @@ -1,5 +1,4 @@ import {ValueOf} from 'type-fest'; -import ClearReportNotifications from '@libs/Notification/clearReportNotifications/types'; import NotificationType, {NotificationDataMap} from './NotificationType'; type Init = () => void; @@ -17,7 +16,6 @@ type PushNotification = { onSelected: OnSelected; TYPE: typeof NotificationType; clearNotifications: ClearNotifications; - clearReportNotifications: ClearReportNotifications; }; export default PushNotification; diff --git a/src/libs/Notification/clearReportNotifications/index.android.ts b/src/libs/Notification/clearReportNotifications/index.android.ts new file mode 100644 index 000000000000..8f0e8cc2ea69 --- /dev/null +++ b/src/libs/Notification/clearReportNotifications/index.android.ts @@ -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; diff --git a/src/libs/Notification/clearReportNotifications/index.ios.ts b/src/libs/Notification/clearReportNotifications/index.ios.ts new file mode 100644 index 000000000000..74b2c7faa50f --- /dev/null +++ b/src/libs/Notification/clearReportNotifications/index.ios.ts @@ -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((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; diff --git a/src/libs/Notification/clearReportNotifications/index.native.ts b/src/libs/Notification/clearReportNotifications/index.native.ts deleted file mode 100644 index 5082fe492564..000000000000 --- a/src/libs/Notification/clearReportNotifications/index.native.ts +++ /dev/null @@ -1,5 +0,0 @@ -import PushNotification from '@libs/Notification/PushNotification'; -import ClearReportNotifications from './types'; - -const clearReportNotifications: ClearReportNotifications = PushNotification.clearReportNotifications; -export default clearReportNotifications;