Skip to content

Commit 427e55e

Browse files
authored
Merge pull request #1647 from OneSignal/fix/remove_summary_notifications
Fix clearing >= 4 groupless notifications
2 parents 5fa6ee2 + f0a10a4 commit 427e55e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotification.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,8 @@ private static void createGrouplessSummaryNotification(
715715
String group = OneSignalNotificationManager.getGrouplessSummaryKey();
716716
String summaryMessage = grouplessNotifCount + " new messages";
717717
int summaryNotificationId = OneSignalNotificationManager.getGrouplessSummaryId();
718+
OneSignalDbHelper dbHelper = OneSignalDbHelper.getInstance(currentContext);
719+
createSummaryIdDatabaseEntry(dbHelper, group, summaryNotificationId);
718720

719721
PendingIntent summaryContentIntent = intentGenerator.getNewActionPendingIntent(
720722
random.nextInt(),

OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,26 @@ public void testFourGrouplessNotificationsUseDefaultGroup() throws Exception {
430430
assertEquals(4, getNotificationsInGroup("os_group_undefined").size());
431431
}
432432

433+
@Test
434+
@Config(sdk = Build.VERSION_CODES.N, shadows = { ShadowGenerateNotification.class })
435+
public void testGrouplessSummaryNotificationIsDismissedOnClear() throws Exception {
436+
OneSignal.setAppId("b2f7f966-d8cc-11e4-bed1-df8f05be55ba");
437+
OneSignal.initWithContext(blankActivity.getApplicationContext());
438+
threadAndTaskWait();
439+
440+
// Add 4 groupless notifications
441+
postNotificationWithOptionalGroup(4, null);
442+
threadAndTaskWait();
443+
444+
// Obtain the posted notifications
445+
Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
446+
assertEquals(5, postedNotifs.size());
447+
// Clear OneSignal Notifications
448+
OneSignal.clearOneSignalNotifications();
449+
threadAndTaskWait();
450+
assertEquals(0, postedNotifs.size());
451+
}
452+
433453
@Test
434454
@Config(sdk = Build.VERSION_CODES.LOLLIPOP, shadows = { ShadowGenerateNotification.class })
435455
public void testNotifDismissAllOnGroupSummaryClickForAndroidUnderM() throws Exception {

0 commit comments

Comments
 (0)