From 20e8d940364460cc37528dd7a4967703c820ce11 Mon Sep 17 00:00:00 2001 From: Jingtai Piao Date: Fri, 9 Aug 2024 09:50:47 +1000 Subject: [PATCH 01/16] Handle if push notification doesn't have a payload --- .../PushNotification/shouldShowPushNotification.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts index 026dcbf4ca4a..969dbe59cb24 100644 --- a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts +++ b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts @@ -14,12 +14,16 @@ export default function shouldShowPushNotification(pushPayload: PushPayload): bo // The payload is string encoded on Android if (typeof payload === 'string') { - payload = JSON.parse(payload) as string; + try { + payload = JSON.parse(payload) as string; + } catch { + Log.info(`[PushNotification] is not able to parse payload. ${payload}`); + } } const data = payload as PushNotificationData; - if (!data.reportID) { + if (!data?.reportID) { Log.info('[PushNotification] Not a report action notification. Showing notification'); return true; } From 144dd4dfba89d5398325fe1723689ce7aa397e1e Mon Sep 17 00:00:00 2001 From: Jingtai Piao Date: Fri, 23 Aug 2024 14:10:52 +1000 Subject: [PATCH 02/16] issue/46820 add more type definitions --- .../shouldShowPushNotification.ts | 21 +++++++++---------- src/types/modules/react-native-airship.d.ts | 10 +++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 src/types/modules/react-native-airship.d.ts diff --git a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts index 969dbe59cb24..a222d3cadd41 100644 --- a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts +++ b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts @@ -1,35 +1,34 @@ -import type {PushPayload} from '@ua/react-native-airship'; +/* eslint-disable prettier/prettier */ +import type {PushPayloadOverride} from '@ua/react-native-airship'; import Log from '@libs/Log'; import * as ReportActionUtils from '@libs/ReportActionsUtils'; import * as Report from '@userActions/Report'; -import type {PushNotificationData} from './NotificationType'; +import type { PushNotificationData } from './NotificationType'; /** * Returns whether the given Airship notification should be shown depending on the current state of the app */ -export default function shouldShowPushNotification(pushPayload: PushPayload): boolean { +export default function shouldShowPushNotification(pushPayload: PushPayloadOverride): boolean { Log.info('[PushNotification] push notification received', false, {pushPayload}); - let payload = pushPayload.extras.payload; + let payload = pushPayload.extras?.payload; // The payload is string encoded on Android if (typeof payload === 'string') { try { - payload = JSON.parse(payload) as string; + payload = JSON.parse(payload) as PushNotificationData; } catch { - Log.info(`[PushNotification] is not able to parse payload. ${payload}`); + Log.hmmm(`[PushNotification] Failed to parse the payload`, payload); } } - const data = payload as PushNotificationData; - - if (!data?.reportID) { + if (!payload || !(payload as PushNotificationData)?.reportID) { Log.info('[PushNotification] Not a report action notification. Showing notification'); return true; } - const reportAction = ReportActionUtils.getLatestReportActionFromOnyxData(data.onyxData ?? null); - const shouldShow = Report.shouldShowReportActionNotification(String(data.reportID), reportAction, true); + const reportAction = ReportActionUtils.getLatestReportActionFromOnyxData((payload as PushNotificationData).onyxData ?? null); + const shouldShow = Report.shouldShowReportActionNotification(String((payload as PushNotificationData).reportID), reportAction, true); Log.info(`[PushNotification] ${shouldShow ? 'Showing' : 'Not showing'} notification`); return shouldShow; } diff --git a/src/types/modules/react-native-airship.d.ts b/src/types/modules/react-native-airship.d.ts new file mode 100644 index 000000000000..ecb64f590f13 --- /dev/null +++ b/src/types/modules/react-native-airship.d.ts @@ -0,0 +1,10 @@ +import '@ua/react-native-airship'; +import type {PushNotificationData} from '@libs/Notification/PushNotification/NotificationType'; + +declare module '@ua/react-native-airship' { + type PushPayloadOverride = Omit & { + extras?: { + payload: PushNotificationData | string; + }; + }; +} From 25217f19cfdcfd84447a0fd83f3eac1a730d229b Mon Sep 17 00:00:00 2001 From: Jingtai Piao Date: Fri, 23 Aug 2024 15:14:30 +1000 Subject: [PATCH 03/16] Revert --- .../shouldShowPushNotification.ts | 17 +++++++++-------- src/types/modules/react-native-airship.d.ts | 10 ---------- 2 files changed, 9 insertions(+), 18 deletions(-) delete mode 100644 src/types/modules/react-native-airship.d.ts diff --git a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts index a222d3cadd41..87497f117189 100644 --- a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts +++ b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts @@ -1,14 +1,13 @@ -/* eslint-disable prettier/prettier */ -import type {PushPayloadOverride} from '@ua/react-native-airship'; +import type {PushPayload} from '@ua/react-native-airship'; import Log from '@libs/Log'; import * as ReportActionUtils from '@libs/ReportActionsUtils'; import * as Report from '@userActions/Report'; -import type { PushNotificationData } from './NotificationType'; +import type {PushNotificationData} from './NotificationType'; /** * Returns whether the given Airship notification should be shown depending on the current state of the app */ -export default function shouldShowPushNotification(pushPayload: PushPayloadOverride): boolean { +export default function shouldShowPushNotification(pushPayload: PushPayload): boolean { Log.info('[PushNotification] push notification received', false, {pushPayload}); let payload = pushPayload.extras?.payload; @@ -16,19 +15,21 @@ export default function shouldShowPushNotification(pushPayload: PushPayloadOverr // The payload is string encoded on Android if (typeof payload === 'string') { try { - payload = JSON.parse(payload) as PushNotificationData; + payload = JSON.parse(payload) as string; } catch { Log.hmmm(`[PushNotification] Failed to parse the payload`, payload); } } - if (!payload || !(payload as PushNotificationData)?.reportID) { + const data = payload ? (payload as PushNotificationData) : undefined; + + if (!data?.reportID) { Log.info('[PushNotification] Not a report action notification. Showing notification'); return true; } - const reportAction = ReportActionUtils.getLatestReportActionFromOnyxData((payload as PushNotificationData).onyxData ?? null); - const shouldShow = Report.shouldShowReportActionNotification(String((payload as PushNotificationData).reportID), reportAction, true); + const reportAction = ReportActionUtils.getLatestReportActionFromOnyxData(data.onyxData ?? null); + const shouldShow = Report.shouldShowReportActionNotification(String(data.reportID), reportAction, true); Log.info(`[PushNotification] ${shouldShow ? 'Showing' : 'Not showing'} notification`); return shouldShow; } diff --git a/src/types/modules/react-native-airship.d.ts b/src/types/modules/react-native-airship.d.ts deleted file mode 100644 index ecb64f590f13..000000000000 --- a/src/types/modules/react-native-airship.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import '@ua/react-native-airship'; -import type {PushNotificationData} from '@libs/Notification/PushNotification/NotificationType'; - -declare module '@ua/react-native-airship' { - type PushPayloadOverride = Omit & { - extras?: { - payload: PushNotificationData | string; - }; - }; -} From 4d55652f542018df7c2bc3fcd3d8d983b70deaa7 Mon Sep 17 00:00:00 2001 From: Jingtai Piao Date: Fri, 23 Aug 2024 15:15:43 +1000 Subject: [PATCH 04/16] Update based on comment --- .../Notification/PushNotification/shouldShowPushNotification.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts index 87497f117189..dd99552bdc52 100644 --- a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts +++ b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts @@ -18,6 +18,7 @@ export default function shouldShowPushNotification(pushPayload: PushPayload): bo payload = JSON.parse(payload) as string; } catch { Log.hmmm(`[PushNotification] Failed to parse the payload`, payload); + payload = {}; } } From 1529b3cfc4bfa96c73d7e379318c6902ea4bc631 Mon Sep 17 00:00:00 2001 From: Jingtai Piao Date: Sat, 24 Aug 2024 03:18:33 +1000 Subject: [PATCH 05/16] Add patch file --- patches/@ua+react-native-airship+17.2.1.patch | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 patches/@ua+react-native-airship+17.2.1.patch diff --git a/patches/@ua+react-native-airship+17.2.1.patch b/patches/@ua+react-native-airship+17.2.1.patch new file mode 100644 index 000000000000..d5b6c1c441a7 --- /dev/null +++ b/patches/@ua+react-native-airship+17.2.1.patch @@ -0,0 +1,13 @@ +diff --git a/node_modules/@ua/react-native-airship/src/types.ts b/node_modules/@ua/react-native-airship/src/types.ts +index 1514436..cec598f 100644 +--- a/node_modules/@ua/react-native-airship/src/types.ts ++++ b/node_modules/@ua/react-native-airship/src/types.ts +@@ -7,7 +7,7 @@ export type JsonValue = + | JsonArray; + + export type JsonObject = { +- [key: string]: JsonValue; ++ [key: string]: JsonValue | undefined; + }; + + export type JsonArray = JsonValue[]; From c819ec0d8af783558c277420aa878a1bcbc52325 Mon Sep 17 00:00:00 2001 From: Jingtai Piao Date: Sat, 24 Aug 2024 06:09:59 +1000 Subject: [PATCH 06/16] Update based on review --- patches/@ua+react-native-airship+17.2.1.patch | 19 +++++++++---------- .../shouldShowPushNotification.ts | 8 ++++---- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/patches/@ua+react-native-airship+17.2.1.patch b/patches/@ua+react-native-airship+17.2.1.patch index d5b6c1c441a7..a41ab2582462 100644 --- a/patches/@ua+react-native-airship+17.2.1.patch +++ b/patches/@ua+react-native-airship+17.2.1.patch @@ -1,13 +1,12 @@ -diff --git a/node_modules/@ua/react-native-airship/src/types.ts b/node_modules/@ua/react-native-airship/src/types.ts -index 1514436..cec598f 100644 ---- a/node_modules/@ua/react-native-airship/src/types.ts -+++ b/node_modules/@ua/react-native-airship/src/types.ts -@@ -7,7 +7,7 @@ export type JsonValue = - | JsonArray; - +diff --git a/node_modules/@ua/react-native-airship/lib/typescript/types.d.ts b/node_modules/@ua/react-native-airship/lib/typescript/types.d.ts +index 9e21186..1e7f466 100644 +--- a/node_modules/@ua/react-native-airship/lib/typescript/types.d.ts ++++ b/node_modules/@ua/react-native-airship/lib/typescript/types.d.ts +@@ -1,6 +1,6 @@ + export type JsonValue = string | number | boolean | null | JsonObject | JsonArray; export type JsonObject = { -- [key: string]: JsonValue; -+ [key: string]: JsonValue | undefined; +- [key: string]: JsonValue; ++ [key: string]: JsonValue | undefined; }; - export type JsonArray = JsonValue[]; + export interface ChannelCreatedEvent { diff --git a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts index dd99552bdc52..02a590cafdf4 100644 --- a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts +++ b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts @@ -1,4 +1,4 @@ -import type {PushPayload} from '@ua/react-native-airship'; +import type {JsonObject, PushPayload} from '@ua/react-native-airship'; import Log from '@libs/Log'; import * as ReportActionUtils from '@libs/ReportActionsUtils'; import * as Report from '@userActions/Report'; @@ -10,15 +10,15 @@ import type {PushNotificationData} from './NotificationType'; export default function shouldShowPushNotification(pushPayload: PushPayload): boolean { Log.info('[PushNotification] push notification received', false, {pushPayload}); - let payload = pushPayload.extras?.payload; + let payload = pushPayload.extras.payload; // The payload is string encoded on Android if (typeof payload === 'string') { try { - payload = JSON.parse(payload) as string; + payload = JSON.parse(payload) as JsonObject; } catch { Log.hmmm(`[PushNotification] Failed to parse the payload`, payload); - payload = {}; + payload = undefined; } } From 0b013983aad154886ade03174c803a3c11a3f910 Mon Sep 17 00:00:00 2001 From: Jingtai Piao Date: Sat, 24 Aug 2024 06:40:47 +1000 Subject: [PATCH 07/16] cast to string to keep consistent to other places --- .../PushNotification/shouldShowPushNotification.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts index 02a590cafdf4..eaf121d47d31 100644 --- a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts +++ b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts @@ -1,4 +1,4 @@ -import type {JsonObject, PushPayload} from '@ua/react-native-airship'; +import type {PushPayload} from '@ua/react-native-airship'; import Log from '@libs/Log'; import * as ReportActionUtils from '@libs/ReportActionsUtils'; import * as Report from '@userActions/Report'; @@ -15,7 +15,7 @@ export default function shouldShowPushNotification(pushPayload: PushPayload): bo // The payload is string encoded on Android if (typeof payload === 'string') { try { - payload = JSON.parse(payload) as JsonObject; + payload = JSON.parse(payload) as string; } catch { Log.hmmm(`[PushNotification] Failed to parse the payload`, payload); payload = undefined; From 91a50c876ec355f189cb59f795e138d974afcd4d Mon Sep 17 00:00:00 2001 From: Jingtai Piao Date: Sat, 24 Aug 2024 08:30:01 +1000 Subject: [PATCH 08/16] Apply payload extract logic to other places and install new react-native-ariship version, --- package-lock.json | 7 ++++--- package.json | 2 +- patches/@ua+react-native-airship+17.2.1.patch | 12 ------------ .../Notification/PushNotification/index.native.ts | 9 +++++++-- .../clearReportNotifications/index.native.ts | 12 +++++++++--- 5 files changed, 21 insertions(+), 21 deletions(-) delete mode 100644 patches/@ua+react-native-airship+17.2.1.patch diff --git a/package-lock.json b/package-lock.json index 9d41bf183372..fb43c43dbe73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46,7 +46,7 @@ "@rnmapbox/maps": "10.1.26", "@shopify/flash-list": "1.6.3", "@types/mime-db": "^1.43.5", - "@ua/react-native-airship": "17.2.1", + "@ua/react-native-airship": "19.2.1", "@vue/preload-webpack-plugin": "^2.0.0", "awesome-phonenumber": "^5.4.0", "babel-polyfill": "^6.26.0", @@ -18631,8 +18631,9 @@ } }, "node_modules/@ua/react-native-airship": { - "version": "17.2.1", - "license": "Apache-2.0", + "version": "19.2.1", + "resolved": "https://registry.npmjs.org/@ua/react-native-airship/-/react-native-airship-19.2.1.tgz", + "integrity": "sha512-DnSTR31OIUWypbUmdtbz7VyXAp+2c7737EKmfG5o2LVDkBNnJ8hO5/2G4eEGmkBLn5tv2zP8vP6nUmq8Pt2wCA==", "engines": { "node": ">= 16.0.0" }, diff --git a/package.json b/package.json index a779dd530fda..1f23a88c5f4b 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,7 @@ "@rnmapbox/maps": "10.1.26", "@shopify/flash-list": "1.6.3", "@types/mime-db": "^1.43.5", - "@ua/react-native-airship": "17.2.1", + "@ua/react-native-airship": "19.2.1", "@vue/preload-webpack-plugin": "^2.0.0", "awesome-phonenumber": "^5.4.0", "babel-polyfill": "^6.26.0", diff --git a/patches/@ua+react-native-airship+17.2.1.patch b/patches/@ua+react-native-airship+17.2.1.patch deleted file mode 100644 index a41ab2582462..000000000000 --- a/patches/@ua+react-native-airship+17.2.1.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/node_modules/@ua/react-native-airship/lib/typescript/types.d.ts b/node_modules/@ua/react-native-airship/lib/typescript/types.d.ts -index 9e21186..1e7f466 100644 ---- a/node_modules/@ua/react-native-airship/lib/typescript/types.d.ts -+++ b/node_modules/@ua/react-native-airship/lib/typescript/types.d.ts -@@ -1,6 +1,6 @@ - export type JsonValue = string | number | boolean | null | JsonObject | JsonArray; - export type JsonObject = { -- [key: string]: JsonValue; -+ [key: string]: JsonValue | undefined; - }; - export type JsonArray = JsonValue[]; - export interface ChannelCreatedEvent { diff --git a/src/libs/Notification/PushNotification/index.native.ts b/src/libs/Notification/PushNotification/index.native.ts index f8500e35995e..5a488bd9fd61 100644 --- a/src/libs/Notification/PushNotification/index.native.ts +++ b/src/libs/Notification/PushNotification/index.native.ts @@ -31,10 +31,15 @@ function pushNotificationEventCallback(eventType: EventType, notification: PushP // On Android, some notification payloads are sent as a JSON string rather than an object if (typeof payload === 'string') { - payload = JSON.parse(payload) as string; + try { + payload = JSON.parse(payload) as string; + } catch { + Log.hmmm(`[PushNotification] Failed to parse the payload`, payload); + payload = undefined; + } } - const data = payload as PushNotificationData; + const data = payload ? (payload as PushNotificationData) : undefined; Log.info(`[PushNotification] Callback triggered for ${eventType}`); diff --git a/src/libs/Notification/clearReportNotifications/index.native.ts b/src/libs/Notification/clearReportNotifications/index.native.ts index aabd24719ea8..c38acf895767 100644 --- a/src/libs/Notification/clearReportNotifications/index.native.ts +++ b/src/libs/Notification/clearReportNotifications/index.native.ts @@ -8,12 +8,18 @@ import type ClearReportNotifications from './types'; const parseNotificationAndReportIDs = (pushPayload: PushPayload) => { let payload = pushPayload.extras.payload; if (typeof payload === 'string') { - payload = JSON.parse(payload) as string; + try { + payload = JSON.parse(payload) as string; + } catch { + Log.hmmm(`[PushNotification] Failed to parse the payload`, payload); + payload = undefined; + } } - const data = payload as PushNotificationData; + + const data = payload ? (payload as PushNotificationData) : undefined; return { notificationID: pushPayload.notificationId, - reportID: String(data.reportID), + reportID: String(data?.reportID), }; }; From ee233224061eb627458df57202ef5393ae205610 Mon Sep 17 00:00:00 2001 From: Jingtai Piao Date: Sat, 24 Aug 2024 08:58:30 +1000 Subject: [PATCH 09/16] Bump react-native-airship version --- ios/Podfile.lock | 112 ++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 59 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index e480ff8231e5..e7eb21fe6950 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -1,30 +1,30 @@ PODS: - - Airship (17.7.3): - - Airship/Automation (= 17.7.3) - - Airship/Basement (= 17.7.3) - - Airship/Core (= 17.7.3) - - Airship/FeatureFlags (= 17.7.3) - - Airship/MessageCenter (= 17.7.3) - - Airship/PreferenceCenter (= 17.7.3) - - Airship/Automation (17.7.3): + - Airship (18.7.2): + - Airship/Automation (= 18.7.2) + - Airship/Basement (= 18.7.2) + - Airship/Core (= 18.7.2) + - Airship/FeatureFlags (= 18.7.2) + - Airship/MessageCenter (= 18.7.2) + - Airship/PreferenceCenter (= 18.7.2) + - Airship/Automation (18.7.2): - Airship/Core - - Airship/Basement (17.7.3) - - Airship/Core (17.7.3): + - Airship/Basement (18.7.2) + - Airship/Core (18.7.2): - Airship/Basement - - Airship/FeatureFlags (17.7.3): + - Airship/FeatureFlags (18.7.2): - Airship/Core - - Airship/MessageCenter (17.7.3): + - Airship/MessageCenter (18.7.2): - Airship/Core - - Airship/PreferenceCenter (17.7.3): + - Airship/PreferenceCenter (18.7.2): - Airship/Core - - AirshipFrameworkProxy (5.1.1): - - Airship (= 17.7.3) - - AirshipServiceExtension (18.6.0) - - AppAuth (1.7.5): - - AppAuth/Core (= 1.7.5) - - AppAuth/ExternalUserAgent (= 1.7.5) - - AppAuth/Core (1.7.5) - - AppAuth/ExternalUserAgent (1.7.5): + - AirshipFrameworkProxy (7.1.2): + - Airship (= 18.7.2) + - AirshipServiceExtension (17.8.0) + - AppAuth (1.6.2): + - AppAuth/Core (= 1.6.2) + - AppAuth/ExternalUserAgent (= 1.6.2) + - AppAuth/Core (1.6.2) + - AppAuth/ExternalUserAgent (1.6.2): - AppAuth/Core - boost (1.84.0) - BVLinearGradient (2.8.1): @@ -1525,6 +1525,8 @@ PODS: - React-debug - React-microtasksnativemodule (0.75.2): - DoubleConversion + - react-native-airship (19.2.1): + - AirshipFrameworkProxy (= 7.1.2) - glog - hermes-engine - RCT-Folly (= 2024.01.01.00) @@ -3053,11 +3055,11 @@ CHECKOUT OPTIONS: :http: https://ios-releases.fullstory.com/fullstory-1.49.0-xcframework.tar.gz SPEC CHECKSUMS: - Airship: 5a6d3f8a982398940b0d48423bb9b8736717c123 - AirshipFrameworkProxy: 7255f4ed9836dc2920f2f1ea5657ced4cee8a35c - AirshipServiceExtension: 74cd5af1c80924bbaa7886fad8609c048210cba3 - AppAuth: 501c04eda8a8d11f179dbe8637b7a91bb7e5d2fa - boost: 26992d1adf73c1c7676360643e687aee6dda994b + Airship: bb32ff2c5a811352da074480357d9f02dbb8f327 + AirshipFrameworkProxy: dbd862dc6fb21b13e8b196458d626123e2a43a50 + AirshipServiceExtension: 0a5fb14c3fd1879355ab05a81d10f64512a4f79c + AppAuth: 3bb1d1cd9340bd09f5ed189fb00b1cc28e1e8570 + boost: d3f49c53809116a5d38da093a8aa78bf551aed09 BVLinearGradient: 421743791a59d259aec53f4c58793aad031da2ca DoubleConversion: 76ab83afb40bddeeee456813d9c04f67f78771b5 EXAV: 62e66b067185d630fe4cb4aa6eb0e48f72e67e0f @@ -3102,39 +3104,31 @@ SPEC CHECKSUMS: onfido-react-native-sdk: 4ccfdeb10f9ccb4a5799d2555cdbc2a068a42c0d Plaid: c32f22ffce5ec67c9e6147eaf6c4d7d5f8086d89 PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47 - RCT-Folly: 4464f4d875961fce86008d45f4ecf6cef6de0740 - RCTDeprecation: 34cbf122b623037ea9facad2e92e53434c5c7422 - RCTRequired: 24c446d7bcd0f517d516b6265d8df04dc3eb1219 - RCTTypeSafety: ef5e91bd791abd3a99b2c75fd565791102a66352 - React: 643f06bc294806d2db2526b424fdf759e107f514 - React-callinvoker: 34d1fa0c340104f324e2521f546196beb44dfad2 - React-Codegen: 4b8b4817cea7a54b83851d4c1f91f79aa73de30a - React-Core: facd883836d8d1cc1949d2053c58eab5fb22eb75 - React-CoreModules: f92a2cb11d22f6066823ca547c61e900325dfe44 - React-cxxreact: f5595a4cbfe5a4e9d401dffa2c1c78bbbbbe75e4 - React-debug: 4a91c177b5b2efcc546fb50bc2f676f3f589efab - React-defaultsnativemodule: 6b666572abf5fe7fe87836a42776abd6ad5ed173 - React-domnativemodule: 785d767c4edbb9f011b8c976271077759ca5c4aa - React-Fabric: a33cc1fdc62a3085774783bb30970531589d2028 - React-FabricComponents: 98de5f94cbd35d407f4fc78855298b562d8289cb - React-FabricImage: 0ce8fd83844d9edef5825116d38f0e208b9ad786 - React-featureflags: 37a78859ad71db758e2efdcbdb7384afefa8701e - React-featureflagsnativemodule: f94aacb52c463e200ee185bff90ae3b392e60263 - React-graphics: c16f1bab97a5d473831a79360d84300e93a614e5 - React-hermes: 7801f8c0e12f326524b461dc368d3e74f3d2a385 - React-idlecallbacksnativemodule: d81bb7b5d26cea9852a8edc6ad1979cd7ed0841f - React-ImageManager: 98a1e5b0b05528dde47ebcd953d916ac66d46c09 - React-jserrorhandler: 08f1c3465a71a6549c27ad82809ce145ad52d4f1 - React-jsi: 161428ab2c706d5fcd9878d260ff1513fdb356ab - React-jsiexecutor: abfdc7526151c6755f836235bbaa53b267a0803c - React-jsinspector: f0786053a1a258a4d8dde859d1a820c26ee686f0 - React-jsitracing: 52b849a77d02e2dc262a3031454c23be8dabb4d9 - React-logger: 8db32983d75dc2ad54f278f344ccb9b256e694fc - React-Mapbuffer: 1c08607305558666fd16678b85ef135e455d5c96 - React-microtasksnativemodule: f13f03163b6a5ec66665dfe80a0df4468bb766a6 - react-native-airship: eec8df1e4824d93569fff42d7ed5a4cdb56a1b86 - react-native-blob-util: 221c61c98ae507b758472ac4d2d489119d1a6c44 - react-native-cameraroll: 478a0c1fcdd39f08f6ac272b7ed06e92b2c7c129 + RCT-Folly: 7169b2b1c44399c76a47b5deaaba715eeeb476c0 + RCTRequired: ab7f915c15569f04a49669e573e6e319a53f9faa + RCTTypeSafety: 63b97ced7b766865057e7154db0e81ce4ee6cf1e + React: 1c87497e50fa40ba9c54e5ea5e53483a0f8eecc0 + React-callinvoker: e3a52a9a93e3eb004d7282c26a4fb27003273fe6 + React-Codegen: 05f85e0e087f402978cfe57822a8debc07127a13 + React-Core: d0ecde72894b792cb8922efaa0990199cbe85169 + React-CoreModules: 2ff1684dd517f0c441495d90a704d499f05e9d0a + React-cxxreact: d9be2fac926741052395da0a6d0bab8d71e2f297 + React-debug: 4678e73a37cb501d784e99ff0f219b4940362a3b + React-Fabric: 460ee9d4b8b9de3382504a711430bfead1d5be1e + React-FabricImage: d0a0631bc8ad9143f42bfccf9d3d533a144cc3d6 + React-graphics: f0d5040263a9649e2a70ebe27b3120c49411afef + React-hermes: b9ac2f7b0c1eeb206eb883583cab7a973d570a6e + React-ImageManager: 6c4bf9d5ed363ead7b5aaf820a3feab221b7063e + React-jserrorhandler: 6e7a7e187583e14dc7a0053a2bdd66c252ea3b21 + React-jsi: 380cd24dd81a705dd042c18989fb10b07182210c + React-jsiexecutor: 8ed7a18b9f119440efdcd424c8257dc7e18067e2 + React-jsinspector: 9ac353eccf6ab54d1e0a33862ba91221d1e88460 + React-jsitracing: e8a2dafb9878dbcad02b6b2b88e66267fb427b74 + React-logger: 0a57b68dd2aec7ff738195f081f0520724b35dab + React-Mapbuffer: 63913773ed7f96b814a2521e13e6d010282096ad + react-native-airship: 99a78474688e1aea78f449ee46a1a3cb24876617 + react-native-blob-util: 1ddace5234c62e3e6e4e154d305ad07ef686599b + react-native-cameraroll: f373bebbe9f6b7c3fd2a6f97c5171cda574cf957 react-native-config: 5ce986133b07fc258828b20b9506de0e683efc1c react-native-document-picker: 2789e41dc92aa3256455aa54639a42f4dc4ee824 react-native-geolocation: b9bd12beaf0ebca61a01514517ca8455bd26fa06 From a27a0f2b718f19d8beb06d9af6c7ee0a8b48c530 Mon Sep 17 00:00:00 2001 From: Jing Tai Piao Date: Sat, 24 Aug 2024 12:55:31 +1000 Subject: [PATCH 10/16] Update src/libs/Notification/PushNotification/index.native.ts Co-authored-by: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> --- src/libs/Notification/PushNotification/index.native.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Notification/PushNotification/index.native.ts b/src/libs/Notification/PushNotification/index.native.ts index 5a488bd9fd61..c98efd6315df 100644 --- a/src/libs/Notification/PushNotification/index.native.ts +++ b/src/libs/Notification/PushNotification/index.native.ts @@ -32,7 +32,7 @@ function pushNotificationEventCallback(eventType: EventType, notification: PushP // On Android, some notification payloads are sent as a JSON string rather than an object if (typeof payload === 'string') { try { - payload = JSON.parse(payload) as string; + payload = JSON.parse(payload) as JsonObject; } catch { Log.hmmm(`[PushNotification] Failed to parse the payload`, payload); payload = undefined; From 3be703d142d4b5169b2c029080bf09473dddc01e Mon Sep 17 00:00:00 2001 From: Jingtai Piao Date: Sat, 24 Aug 2024 12:57:22 +1000 Subject: [PATCH 11/16] Update based on review --- src/libs/Notification/clearReportNotifications/index.native.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Notification/clearReportNotifications/index.native.ts b/src/libs/Notification/clearReportNotifications/index.native.ts index c38acf895767..6930d2aede3a 100644 --- a/src/libs/Notification/clearReportNotifications/index.native.ts +++ b/src/libs/Notification/clearReportNotifications/index.native.ts @@ -19,7 +19,7 @@ const parseNotificationAndReportIDs = (pushPayload: PushPayload) => { const data = payload ? (payload as PushNotificationData) : undefined; return { notificationID: pushPayload.notificationId, - reportID: String(data?.reportID), + reportID: data?.reportID ? String(data.reportID) : undefined, }; }; From 930b9ac08b8eadc8af381d4f041f4927c5b34e5a Mon Sep 17 00:00:00 2001 From: Jingtai Piao Date: Sat, 24 Aug 2024 15:08:44 +1000 Subject: [PATCH 12/16] Add missing import --- src/libs/Notification/PushNotification/index.native.ts | 2 +- .../PushNotification/shouldShowPushNotification.ts | 4 ++-- .../Notification/clearReportNotifications/index.native.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/Notification/PushNotification/index.native.ts b/src/libs/Notification/PushNotification/index.native.ts index c98efd6315df..351e4de28ae8 100644 --- a/src/libs/Notification/PushNotification/index.native.ts +++ b/src/libs/Notification/PushNotification/index.native.ts @@ -1,4 +1,4 @@ -import type {PushPayload} from '@ua/react-native-airship'; +import type {JsonObject, PushPayload} from '@ua/react-native-airship'; import Airship, {EventType} from '@ua/react-native-airship'; import Onyx from 'react-native-onyx'; import Log from '@libs/Log'; diff --git a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts index eaf121d47d31..02a590cafdf4 100644 --- a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts +++ b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts @@ -1,4 +1,4 @@ -import type {PushPayload} from '@ua/react-native-airship'; +import type {JsonObject, PushPayload} from '@ua/react-native-airship'; import Log from '@libs/Log'; import * as ReportActionUtils from '@libs/ReportActionsUtils'; import * as Report from '@userActions/Report'; @@ -15,7 +15,7 @@ export default function shouldShowPushNotification(pushPayload: PushPayload): bo // The payload is string encoded on Android if (typeof payload === 'string') { try { - payload = JSON.parse(payload) as string; + payload = JSON.parse(payload) as JsonObject; } catch { Log.hmmm(`[PushNotification] Failed to parse the payload`, payload); payload = undefined; diff --git a/src/libs/Notification/clearReportNotifications/index.native.ts b/src/libs/Notification/clearReportNotifications/index.native.ts index 6930d2aede3a..85a863f3b40d 100644 --- a/src/libs/Notification/clearReportNotifications/index.native.ts +++ b/src/libs/Notification/clearReportNotifications/index.native.ts @@ -1,4 +1,4 @@ -import type {PushPayload} from '@ua/react-native-airship'; +import type {JsonObject, PushPayload} from '@ua/react-native-airship'; import Airship from '@ua/react-native-airship'; import Log from '@libs/Log'; import type {PushNotificationData} from '@libs/Notification/PushNotification/NotificationType'; @@ -9,7 +9,7 @@ const parseNotificationAndReportIDs = (pushPayload: PushPayload) => { let payload = pushPayload.extras.payload; if (typeof payload === 'string') { try { - payload = JSON.parse(payload) as string; + payload = JSON.parse(payload) as JsonObject; } catch { Log.hmmm(`[PushNotification] Failed to parse the payload`, payload); payload = undefined; From 98dbb883f354e40b2146649967bb650b974f4c29 Mon Sep 17 00:00:00 2001 From: Jing Tai Piao Date: Sat, 24 Aug 2024 17:41:46 +1000 Subject: [PATCH 13/16] Update src/libs/Notification/clearReportNotifications/index.native.ts Co-authored-by: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> --- src/libs/Notification/clearReportNotifications/index.native.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Notification/clearReportNotifications/index.native.ts b/src/libs/Notification/clearReportNotifications/index.native.ts index 85a863f3b40d..85e815a721c2 100644 --- a/src/libs/Notification/clearReportNotifications/index.native.ts +++ b/src/libs/Notification/clearReportNotifications/index.native.ts @@ -19,7 +19,7 @@ const parseNotificationAndReportIDs = (pushPayload: PushPayload) => { const data = payload ? (payload as PushNotificationData) : undefined; return { notificationID: pushPayload.notificationId, - reportID: data?.reportID ? String(data.reportID) : undefined, + reportID: data?.reportID !== undefined ? String(data.reportID) : undefined, }; }; From 0c329dd6abeade15f0085c4d1640849e23f7a07f Mon Sep 17 00:00:00 2001 From: Jing Tai Piao Date: Sun, 25 Aug 2024 08:02:04 +1000 Subject: [PATCH 14/16] Update src/libs/Notification/PushNotification/shouldShowPushNotification.ts Co-authored-by: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> --- .../Notification/PushNotification/shouldShowPushNotification.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts index 02a590cafdf4..a96cba5386aa 100644 --- a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts +++ b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts @@ -24,7 +24,7 @@ export default function shouldShowPushNotification(pushPayload: PushPayload): bo const data = payload ? (payload as PushNotificationData) : undefined; - if (!data?.reportID) { + if (data?.reportID === undefined) { Log.info('[PushNotification] Not a report action notification. Showing notification'); return true; } From f8188b0e9c8674e016c38196b3f23a3ed07d7cc4 Mon Sep 17 00:00:00 2001 From: Jingtai Piao Date: Tue, 27 Aug 2024 05:23:14 +1000 Subject: [PATCH 15/16] Extract parse payload to a function --- .../PushNotification/index.native.ts | 16 +++----------- .../parsePushNotificationPayload.ts | 20 ++++++++++++++++++ .../shouldShowPushNotification.ts | 21 ++++--------------- .../clearReportNotifications/index.native.ts | 16 +++----------- 4 files changed, 30 insertions(+), 43 deletions(-) create mode 100644 src/libs/Notification/PushNotification/parsePushNotificationPayload.ts diff --git a/src/libs/Notification/PushNotification/index.native.ts b/src/libs/Notification/PushNotification/index.native.ts index 351e4de28ae8..334317ec5d0a 100644 --- a/src/libs/Notification/PushNotification/index.native.ts +++ b/src/libs/Notification/PushNotification/index.native.ts @@ -1,4 +1,4 @@ -import type {JsonObject, PushPayload} from '@ua/react-native-airship'; +import type {PushPayload} from '@ua/react-native-airship'; import Airship, {EventType} from '@ua/react-native-airship'; import Onyx from 'react-native-onyx'; import Log from '@libs/Log'; @@ -7,6 +7,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ForegroundNotifications from './ForegroundNotifications'; import type {PushNotificationData} from './NotificationType'; import NotificationType from './NotificationType'; +import parsePushNotificationPayload from './parsePushNotificationPayload'; import type {ClearNotifications, Deregister, Init, OnReceived, OnSelected, Register} from './types'; import type PushNotificationType from './types'; @@ -27,19 +28,8 @@ const notificationEventActionMap: NotificationEventActionMap = {}; */ function pushNotificationEventCallback(eventType: EventType, notification: PushPayload) { const actionMap = notificationEventActionMap[eventType] ?? {}; - let payload = notification.extras.payload; - - // On Android, some notification payloads are sent as a JSON string rather than an object - if (typeof payload === 'string') { - try { - payload = JSON.parse(payload) as JsonObject; - } catch { - Log.hmmm(`[PushNotification] Failed to parse the payload`, payload); - payload = undefined; - } - } - const data = payload ? (payload as PushNotificationData) : undefined; + const data = parsePushNotificationPayload(notification.extras.payload); Log.info(`[PushNotification] Callback triggered for ${eventType}`); diff --git a/src/libs/Notification/PushNotification/parsePushNotificationPayload.ts b/src/libs/Notification/PushNotification/parsePushNotificationPayload.ts new file mode 100644 index 000000000000..8ef20dd9f537 --- /dev/null +++ b/src/libs/Notification/PushNotification/parsePushNotificationPayload.ts @@ -0,0 +1,20 @@ +import type {JsonObject, JsonValue} from '@ua/react-native-airship'; +import Log from '@libs/Log'; +import type {PushNotificationData} from './NotificationType'; + +/** + * Parse the payload of a push notification. On Android, some notification payloads are sent as a JSON string rather than an object + */ +export default function parsePushNotificationPayload(payload: JsonValue | undefined): PushNotificationData | undefined { + let data = payload; + if (typeof payload === 'string') { + try { + data = JSON.parse(payload) as JsonObject; + } catch { + Log.hmmm(`[PushNotification] Failed to parse the payload`, payload); + data = undefined; + } + } + + return data ? (data as PushNotificationData) : undefined; +} diff --git a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts index a96cba5386aa..6f85975f7b7d 100644 --- a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts +++ b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts @@ -1,28 +1,15 @@ -import type {JsonObject, PushPayload} from '@ua/react-native-airship'; +import type {PushPayload} from '@ua/react-native-airship'; import Log from '@libs/Log'; import * as ReportActionUtils from '@libs/ReportActionsUtils'; import * as Report from '@userActions/Report'; -import type {PushNotificationData} from './NotificationType'; +import parsePushNotificationPayload from './parsePushNotificationPayload'; /** * Returns whether the given Airship notification should be shown depending on the current state of the app */ export default function shouldShowPushNotification(pushPayload: PushPayload): boolean { - Log.info('[PushNotification] push notification received', false, {pushPayload}); - - let payload = pushPayload.extras.payload; - - // The payload is string encoded on Android - if (typeof payload === 'string') { - try { - payload = JSON.parse(payload) as JsonObject; - } catch { - Log.hmmm(`[PushNotification] Failed to parse the payload`, payload); - payload = undefined; - } - } - - const data = payload ? (payload as PushNotificationData) : undefined; + Log.info('[PushNotification] push notification resceived', false, {pushPayload}); + const data = parsePushNotificationPayload(pushPayload.extras.payload); if (data?.reportID === undefined) { Log.info('[PushNotification] Not a report action notification. Showing notification'); diff --git a/src/libs/Notification/clearReportNotifications/index.native.ts b/src/libs/Notification/clearReportNotifications/index.native.ts index 85e815a721c2..ad7d80a5b832 100644 --- a/src/libs/Notification/clearReportNotifications/index.native.ts +++ b/src/libs/Notification/clearReportNotifications/index.native.ts @@ -1,22 +1,12 @@ -import type {JsonObject, PushPayload} from '@ua/react-native-airship'; +import type {PushPayload} from '@ua/react-native-airship'; import Airship from '@ua/react-native-airship'; import Log from '@libs/Log'; -import type {PushNotificationData} from '@libs/Notification/PushNotification/NotificationType'; +import parsePushNotificationPayload from '@libs/Notification/PushNotification/parsePushNotificationPayload'; import CONST from '@src/CONST'; import type ClearReportNotifications from './types'; const parseNotificationAndReportIDs = (pushPayload: PushPayload) => { - let payload = pushPayload.extras.payload; - if (typeof payload === 'string') { - try { - payload = JSON.parse(payload) as JsonObject; - } catch { - Log.hmmm(`[PushNotification] Failed to parse the payload`, payload); - payload = undefined; - } - } - - const data = payload ? (payload as PushNotificationData) : undefined; + const data = parsePushNotificationPayload(pushPayload.extras.payload); return { notificationID: pushPayload.notificationId, reportID: data?.reportID !== undefined ? String(data.reportID) : undefined, From efffbe9c758af31133829c0ab3875e87b53f2cbb Mon Sep 17 00:00:00 2001 From: Jing Tai Piao Date: Tue, 27 Aug 2024 06:01:38 +1000 Subject: [PATCH 16/16] Update src/libs/Notification/PushNotification/shouldShowPushNotification.ts Co-authored-by: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> --- .../Notification/PushNotification/shouldShowPushNotification.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts index 6f85975f7b7d..3bd7bf94c1e2 100644 --- a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts +++ b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts @@ -8,7 +8,7 @@ import parsePushNotificationPayload from './parsePushNotificationPayload'; * Returns whether the given Airship notification should be shown depending on the current state of the app */ export default function shouldShowPushNotification(pushPayload: PushPayload): boolean { - Log.info('[PushNotification] push notification resceived', false, {pushPayload}); + Log.info('[PushNotification] push notification received', false, {pushPayload}); const data = parsePushNotificationPayload(pushPayload.extras.payload); if (data?.reportID === undefined) {