Skip to content

Commit

Permalink
Merge pull request #131 from OneSignal/collapse_id_and_priority
Browse files Browse the repository at this point in the history
Added display priority and collapseId payload property
  • Loading branch information
jkasten2 authored Oct 19, 2016
2 parents a3ba3c3 + eac08ec commit 6fb9285
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ private static NotificationCompat.Builder getBaseNotificationCompatBuilder(JSONO

notifBuilder.setDefaults(notificationDefaults);

if (gcmBundle.optInt("pri", 0) > 9)
notifBuilder.setPriority(NotificationCompat.PRIORITY_MAX);

return notifBuilder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ static OSNotificationPayload OSNotificationPayloadFrom(JSONObject currentJsonPay
if (visibility != null)
notification.lockScreenVisibility = Integer.parseInt(visibility);
notification.fromProjectNumber = currentJsonPayload.optString("from", null);
notification.priority = currentJsonPayload.optInt("pri", 0);
String collapseKey = currentJsonPayload.optString("collapse_key", null);
if (!"do_not_collapse".equals(collapseKey))
notification.collapseId = collapseKey;

try {
setActionButtons(notification);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ public String stringify() {
pay.put("groupMessage", payload.groupMessage);
pay.put("actionButtons", payload.actionButtons);
pay.put("fromProjectNumber", payload.fromProjectNumber);
pay.put("collapseId", payload.collapseId);
pay.put("priority", payload.priority);

pay.put("rawPayload", payload.rawPayload);

mainObj.put("payload", pay);
}
catch(JSONException e) {e.printStackTrace();}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class OSNotificationPayload {
public List<ActionButton> actionButtons;
public String fromProjectNumber;
public BackgroundImageLayout backgroundImageLayout;
public String collapseId;
public int priority;
public String rawPayload;

public static class ActionButton {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1233,10 +1233,8 @@ public static void setLocationShared(boolean enable) {

public static void promptLocation() {

if (!shareLocation) {
// Share location disabled
if (!shareLocation)
return;
}

if (appContext == null) {
Log(LOG_LEVEL.ERROR, "OneSignal.init has not been called. Could not prompt for location.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ public void shouldFireNotificationExtenderService() throws Exception {
Assert.assertEquals("test_sound", notificationPayload.sound);
Assert.assertEquals("You test $[notif_count] MSGs!", notificationPayload.groupMessage);
Assert.assertEquals("http://google.com", notificationPayload.launchURL);
Assert.assertEquals(10, notificationPayload.priority);
Assert.assertEquals("a_key", notificationPayload.collapseId);

Assert.assertEquals("id1", notificationPayload.actionButtons.get(0).id);
Assert.assertEquals("button1", notificationPayload.actionButtons.get(0).text);
Expand Down Expand Up @@ -449,12 +451,12 @@ private static Bundle getBundleWithAllOptionsSet() {
bundle.putString("sicon", "small_icon");
bundle.putString("sound", "test_sound");
bundle.putString("grp_msg", "You test $[notif_count] MSGs!");
bundle.putString("collapse_key", "do_not_collapse");
bundle.putString("collapse_key", "a_key"); // GCM sets this to 'do_not_collapse' when not set.
bundle.putString("bg_img", "{\"img\": \"test_image_url\"," +
"\"tc\": \"FF000000\"," +
"\"bc\": \"FFFFFFFF\"}");


bundle.putInt("pri", 10);
bundle.putString("custom",
"{\"a\": {" +
" \"myKey\": \"myValue\"," +
Expand Down

0 comments on commit 6fb9285

Please sign in to comment.