Skip to content

Commit

Permalink
Merge pull request #1711 from OneSignal/fix/individually_clear_notifi…
Browse files Browse the repository at this point in the history
…cations

Fix individually clearing notifications
  • Loading branch information
jennantilla authored Jan 4, 2023
2 parents d8125db + 7c199a6 commit 4cb7305
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static Cursor internalUpdateSummaryNotificationAfterChildRemoved(Context
// If all individual notifications consumed
// - Remove summary notification from the shade.
// - Mark summary notification as consumed.
if (notificationsInGroup == 0) {
if (notificationsInGroup == 0 && !group.equals(OneSignalNotificationManager.getGrouplessSummaryKey())) {
cursor.close();

Integer androidNotifId = getSummaryNotificationId(db, group);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -450,6 +449,34 @@ public void testGrouplessSummaryNotificationIsDismissedOnClear() throws Exceptio
assertEquals(0, postedNotifs.size());
}

@Test
@Config(sdk = Build.VERSION_CODES.N, shadows = { ShadowGenerateNotification.class })
public void testIndividualGrouplessSummaryNotificationDismissal() throws Exception {
OneSignal.setAppId("b2f7f966-d8cc-11e4-bed1-df8f05be55ba");
OneSignal.initWithContext(blankActivity.getApplicationContext());
threadAndTaskWait();

// Add 4 groupless notifications
postNotificationWithOptionalGroup(4, null);
threadAndTaskWait();

// Obtain the posted notifications
Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
Iterator<Map.Entry<Integer, PostedNotification>> iterator = postedNotifs.entrySet().iterator();
Map.Entry<Integer, PostedNotification> entry = iterator.next();
Map.Entry<Integer, PostedNotification> entry2 = iterator.next();
Map.Entry<Integer, PostedNotification> entry3 = iterator.next();
Map.Entry<Integer, PostedNotification> entry4 = iterator.next();
Integer id4 = entry4.getKey();
assertNotNull(id4);

assertEquals(5, postedNotifs.size());
// Clear a OneSignal Notification
OneSignal.removeNotification(id4);
threadAndTaskWait();
assertEquals(4, postedNotifs.size());
}

@Test
@Config(sdk = Build.VERSION_CODES.LOLLIPOP, shadows = { ShadowGenerateNotification.class })
public void testNotifDismissAllOnGroupSummaryClickForAndroidUnderM() throws Exception {
Expand Down

0 comments on commit 4cb7305

Please sign in to comment.