Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,7 +85,11 @@ public static HashMap<String, Object> convertNotificationToMap(INotification not
if (notification.getGroupedNotifications() != null) {
notificationHash.put("groupKey", notification.getGroupKey());
notificationHash.put("groupMessage", notification.getGroupMessage());
notificationHash.put("groupedNotifications", notification.getGroupedNotifications());
List<Object> groupedNotifications = new ArrayList<>();
for (INotification groupedNotification : notification.getGroupedNotifications()) {
groupedNotifications.add(convertNotificationToMap(groupedNotification));
}
notificationHash.put("groupedNotifications", groupedNotifications);
}

notificationHash.put("notificationId", notification.getNotificationId());
Expand All @@ -111,7 +116,15 @@ public static HashMap<String, Object> convertNotificationToMap(INotification not
&& notification.getAdditionalData().length() > 0)
notificationHash.put("additionalData", convertJSONObjectToHashMap(notification.getAdditionalData()));
if (notification.getActionButtons() != null) {
notificationHash.put("actionButtons", notification.getActionButtons());
List<Object> actionButtons = new ArrayList<>();
for (IActionButton actionButton : notification.getActionButtons()) {
HashMap<String, Object> 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());

Expand Down Expand Up @@ -230,8 +243,6 @@ public static HashMap<String, Object> convertJSONObjectToHashMap(JSONObject obje
while (keys.hasNext()) {
String key = keys.next();

if (object.isNull(key)) continue;

Object val = object.get(key);

if (val instanceof JSONArray) {
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion examples/demo/src/services/OneSignalApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class OneSignalApiService {
async sendNotification(type: NotificationType, subscriptionId: string): Promise<boolean> {
let headings: Record<string, string>;
let contents: Record<string, string>;
const extra: Record<string, unknown> = {};
const extra: Record<string, unknown> = {
android_group: 'demo-group',
};

switch (type) {
case NotificationType.Simple:
Expand Down
7 changes: 7 additions & 0 deletions src/OSNotification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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');
Expand Down
3 changes: 3 additions & 0 deletions src/OSNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface BaseNotificationData {
interface AndroidNotificationData extends BaseNotificationData {
groupKey?: string;
groupMessage?: string;
groupedNotifications?: AndroidNotificationData[];
ledColor?: string;
priority?: number;
smallIcon?: string;
Expand Down Expand Up @@ -58,6 +59,7 @@ export default class OSNotification {
// android only
groupKey?: string;
groupMessage?: string;
groupedNotifications?: AndroidNotificationData[];
ledColor?: string;
priority?: number;
smallIcon?: string;
Expand Down Expand Up @@ -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;
Expand Down
Loading