Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

add grouping support for Android push notifications #25

Open
wants to merge 1 commit into
base: 3.1.2-patch.10
Choose a base branch
from
Open
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 @@ -154,6 +154,11 @@ protected Notification.Builder getNotificationBuilder(PendingIntent intent) {
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true);

final String group = mNotificationProps.getGroup();
if (group != null && !group.isEmpty()) {
notification.setGroup(group);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
CHANNEL_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ public PushNotificationProps() {
mBundle = new Bundle();
}

public PushNotificationProps(String title, String body) {
public PushNotificationProps(String title, String body, String group) {
mBundle = new Bundle();
mBundle.putString("title", title);
mBundle.putString("body", body);
mBundle.putString("group", group);
}

public PushNotificationProps(Bundle bundle) {
Expand All @@ -28,6 +29,10 @@ public String getBody() {
return mBundle.getString("body");
}

public String getGroup() {
return mBundle.getString("group");
}

public Bundle asBundle() {
return (Bundle) mBundle.clone();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class PushNotificationTest {

private static final String DEFAULT_NOTIFICATION_TITLE = "Notification-title";
private static final String DEFAULT_NOTIFICATION_BODY = "Notification-body";
private static final String DEFAULT_NOTIFICATION_GROUP = "Notification-group";

@Mock private ReactContext mReactContext;
@Mock private Context mContext;
Expand All @@ -62,6 +63,7 @@ public void setup() throws Exception {

when(mDefaultBundle.getString(eq("title"))).thenReturn(DEFAULT_NOTIFICATION_TITLE);
when(mDefaultBundle.getString(eq("body"))).thenReturn(DEFAULT_NOTIFICATION_BODY);
when(mDefaultBundle.getString(eq("group"))).thenReturn(DEFAULT_NOTIFICATION_GROUP);
when(mDefaultBundle.clone()).thenReturn(mDefaultBundle);

when(mAppLaunchHelper.getLaunchIntent(eq(mContext))).thenReturn(mLaunchIntent);
Expand Down Expand Up @@ -316,5 +318,6 @@ protected void verifyNotification(Notification notification) {
ShadowNotification shadowNotification = Shadows.shadowOf(notification);
assertEquals(shadowNotification.getContentText(), DEFAULT_NOTIFICATION_BODY);
assertEquals(shadowNotification.getContentTitle(), DEFAULT_NOTIFICATION_TITLE);
assertEquals(shadowNotification.getGroup(), DEFAULT_NOTIFICATION_GROUP);
}
}