|
|
@@ -13,14 +13,25 @@ import {
|
|
|
unregisterBackgroundNotificationTask
|
|
|
} from 'src/utils/pushNotificationTask';
|
|
|
|
|
|
+const safeParseParams = (value: unknown) => {
|
|
|
+ if (typeof value !== 'string') return {};
|
|
|
+ try {
|
|
|
+ const parsed = JSON.parse(value);
|
|
|
+ return parsed && typeof parsed === 'object' ? parsed : {};
|
|
|
+ } catch {
|
|
|
+ console.warn('Invalid notification params JSON', value);
|
|
|
+ return {};
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
const PushNotificationContext = createContext<{
|
|
|
isSubscribed: boolean;
|
|
|
toggleSubscription: () => Promise<void>;
|
|
|
unsubscribeFromNotifications: () => Promise<void>;
|
|
|
}>({
|
|
|
isSubscribed: false,
|
|
|
- toggleSubscription: async () => {},
|
|
|
- unsubscribeFromNotifications: async () => {}
|
|
|
+ toggleSubscription: async () => { },
|
|
|
+ unsubscribeFromNotifications: async () => { }
|
|
|
});
|
|
|
|
|
|
export const usePushNotification = () => useContext(PushNotificationContext);
|
|
|
@@ -181,7 +192,7 @@ export const PushNotificationProvider = ({ children }: { children: React.ReactNo
|
|
|
|
|
|
if (data?.screen && data?.parentScreen) {
|
|
|
if (data?.params) {
|
|
|
- const parsedParams = JSON.parse(data.params) ?? {};
|
|
|
+ const parsedParams = safeParseParams(data?.params);
|
|
|
|
|
|
navigation.dispatch(
|
|
|
CommonActions.reset({
|
|
|
@@ -282,11 +293,9 @@ export const PushNotificationProvider = ({ children }: { children: React.ReactNo
|
|
|
let fromUser;
|
|
|
|
|
|
if (Platform.OS === 'ios') {
|
|
|
- const parsedData =
|
|
|
- JSON.parse(
|
|
|
- (notification.request.trigger as Notifications.PushNotificationTrigger)?.payload
|
|
|
- ?.params as string
|
|
|
- ) ?? {};
|
|
|
+ const parsedData = safeParseParams(
|
|
|
+ (notification.request.trigger as Notifications.PushNotificationTrigger)?.payload?.params
|
|
|
+ );
|
|
|
groupToken = parsedData?.group_token;
|
|
|
messageId = (notification.request.trigger as Notifications.PushNotificationTrigger)
|
|
|
?.payload?.message_id as number;
|
|
|
@@ -313,11 +322,10 @@ export const PushNotificationProvider = ({ children }: { children: React.ReactNo
|
|
|
url = (response.notification.request.trigger as Notifications.PushNotificationTrigger)
|
|
|
?.payload?.url;
|
|
|
}
|
|
|
- console.log('33333', screenName, parentScreen);
|
|
|
|
|
|
if (screenName && parentScreen) {
|
|
|
if (params) {
|
|
|
- const parsedParams = JSON.parse(params as string) ?? {};
|
|
|
+ const parsedParams = safeParseParams(params);
|
|
|
|
|
|
navigation.dispatch(
|
|
|
CommonActions.reset({
|