diff --git a/android/src/main/java/com/onesignal/rnonesignalandroid/RNUtils.java b/android/src/main/java/com/onesignal/rnonesignalandroid/RNUtils.java index 639d5ba0..e6494daf 100644 --- a/android/src/main/java/com/onesignal/rnonesignalandroid/RNUtils.java +++ b/android/src/main/java/com/onesignal/rnonesignalandroid/RNUtils.java @@ -14,6 +14,7 @@ import com.onesignal.inAppMessages.IInAppMessageDidDisplayEvent; import com.onesignal.inAppMessages.IInAppMessageWillDismissEvent; import com.onesignal.inAppMessages.IInAppMessageWillDisplayEvent; +import com.onesignal.notifications.IActionButton; import com.onesignal.notifications.INotification; import com.onesignal.notifications.INotificationClickEvent; import com.onesignal.notifications.INotificationClickResult; @@ -84,7 +85,11 @@ public static HashMap convertNotificationToMap(INotification not if (notification.getGroupedNotifications() != null) { notificationHash.put("groupKey", notification.getGroupKey()); notificationHash.put("groupMessage", notification.getGroupMessage()); - notificationHash.put("groupedNotifications", notification.getGroupedNotifications()); + List groupedNotifications = new ArrayList<>(); + for (INotification groupedNotification : notification.getGroupedNotifications()) { + groupedNotifications.add(convertNotificationToMap(groupedNotification)); + } + notificationHash.put("groupedNotifications", groupedNotifications); } notificationHash.put("notificationId", notification.getNotificationId()); @@ -111,7 +116,15 @@ public static HashMap convertNotificationToMap(INotification not && notification.getAdditionalData().length() > 0) notificationHash.put("additionalData", convertJSONObjectToHashMap(notification.getAdditionalData())); if (notification.getActionButtons() != null) { - notificationHash.put("actionButtons", notification.getActionButtons()); + List actionButtons = new ArrayList<>(); + for (IActionButton actionButton : notification.getActionButtons()) { + HashMap action = new HashMap<>(); + action.put("id", actionButton.getId()); + action.put("text", actionButton.getText()); + action.put("icon", actionButton.getIcon()); + actionButtons.add(action); + } + notificationHash.put("actionButtons", actionButtons); } notificationHash.put("rawPayload", notification.getRawPayload()); @@ -230,8 +243,6 @@ public static HashMap convertJSONObjectToHashMap(JSONObject obje while (keys.hasNext()) { String key = keys.next(); - if (object.isNull(key)) continue; - Object val = object.get(key); if (val instanceof JSONArray) { diff --git a/examples/demo/bun.lock b/examples/demo/bun.lock index e7eb84d5..babdf59d 100644 --- a/examples/demo/bun.lock +++ b/examples/demo/bun.lock @@ -1006,7 +1006,7 @@ "react-native-dotenv": ["react-native-dotenv@3.4.11", "", { "dependencies": { "dotenv": "^16.4.5" }, "peerDependencies": { "@babel/runtime": "^7.20.6" } }, "sha512-6vnIE+WHABSeHCaYP6l3O1BOEhWxKH6nHAdV7n/wKn/sciZ64zPPp2NUdEUf1m7g4uuzlLbjgr+6uDt89q2DOg=="], - "react-native-onesignal": ["react-native-onesignal@../../react-native-onesignal.tgz", { "dependencies": { "invariant": "^2.2.4" }, "peerDependencies": { "react-native": ">=0.79.0" } }, "sha512-BIfiuVckjBMx0p+P+vhRXzLn5cYovtuBysWBcyndV9cZv6YTm8hU4fk/uCf7u2x5dZ0NY4PUTySjkM7knrbvaA=="], + "react-native-onesignal": ["react-native-onesignal@../../react-native-onesignal.tgz", { "dependencies": { "invariant": "^2.2.4" }, "peerDependencies": { "react-native": ">=0.79.0" } }, "sha512-n27/13rn/viQCldBWaxetgH7r7MfbxPhPX4HmLVXE2mVcvEjaFfhLEKf5Jn0YbFltNStubuMOceKji1mmGGHWw=="], "react-native-safe-area-context": ["react-native-safe-area-context@5.7.0", "", { "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-/9/MtQz8ODphjsLdZ+GZAIcC/RtoqW9EeShf7Uvnfgm/pzYrJ75y3PV/J1wuAV1T5Dye5ygq4EAW20RoBq0ABQ=="], diff --git a/examples/demo/src/services/OneSignalApiService.ts b/examples/demo/src/services/OneSignalApiService.ts index 75d1bb9e..ffadd923 100644 --- a/examples/demo/src/services/OneSignalApiService.ts +++ b/examples/demo/src/services/OneSignalApiService.ts @@ -43,7 +43,9 @@ class OneSignalApiService { async sendNotification(type: NotificationType, subscriptionId: string): Promise { let headings: Record; let contents: Record; - const extra: Record = {}; + const extra: Record = { + android_group: 'demo-group', + }; switch (type) { case NotificationType.Simple: diff --git a/src/OSNotification.test.ts b/src/OSNotification.test.ts index fbae061a..75e0aac5 100644 --- a/src/OSNotification.test.ts +++ b/src/OSNotification.test.ts @@ -59,10 +59,16 @@ describe('OSNotification', () => { }); test('should initialize Android-specific properties on Android platform', () => { + const groupedNotification = { + body: 'Grouped notification', + rawPayload: {}, + notificationId: 'grouped-notification-id', + }; const androidData = { ...baseNotificationData, groupKey: 'group-1', groupMessage: 'group message', + groupedNotifications: [groupedNotification], ledColor: 'FFFF0000', priority: 2, smallIcon: 'icon_small', @@ -78,6 +84,7 @@ describe('OSNotification', () => { expect(notification.groupKey).toBe('group-1'); expect(notification.groupMessage).toBe('group message'); + expect(notification.groupedNotifications).toEqual([groupedNotification]); expect(notification.ledColor).toBe('FFFF0000'); expect(notification.priority).toBe(2); expect(notification.smallIcon).toBe('icon_small'); diff --git a/src/OSNotification.ts b/src/OSNotification.ts index 060f79a9..646f8a29 100644 --- a/src/OSNotification.ts +++ b/src/OSNotification.ts @@ -17,6 +17,7 @@ export interface BaseNotificationData { interface AndroidNotificationData extends BaseNotificationData { groupKey?: string; groupMessage?: string; + groupedNotifications?: AndroidNotificationData[]; ledColor?: string; priority?: number; smallIcon?: string; @@ -58,6 +59,7 @@ export default class OSNotification { // android only groupKey?: string; groupMessage?: string; + groupedNotifications?: AndroidNotificationData[]; ledColor?: string; priority?: number; smallIcon?: string; @@ -102,6 +104,7 @@ export default class OSNotification { this.bigPicture = receivedEvent.bigPicture; this.collapseId = receivedEvent.collapseId; this.groupMessage = receivedEvent.groupMessage; + this.groupedNotifications = receivedEvent.groupedNotifications; this.fromProjectNumber = receivedEvent.fromProjectNumber; this.smallIconAccentColor = receivedEvent.smallIconAccentColor; this.lockScreenVisibility = receivedEvent.lockScreenVisibility;