-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47123 from jp928/jp928/issue/46820
Handle if push notification doesn't have a payload
- Loading branch information
Showing
7 changed files
with
86 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/libs/Notification/PushNotification/parsePushNotificationPayload.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 3 additions & 7 deletions
10
src/libs/Notification/clearReportNotifications/index.native.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters