Skip to content

Commit

Permalink
#19 APNS notification mutable-content attribute specification through…
Browse files Browse the repository at this point in the history
… FCM needed to be done differently, fixed.
  • Loading branch information
Eric Bariaux committed Oct 19, 2017
1 parent 0533cb1 commit a904b76
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@
*/
package org.openremote.manager.server.notification;

import com.fasterxml.jackson.annotation.JsonProperty;

public class FCMMessage extends FCMBaseMessage {

protected Notification notification;
protected boolean contentAvailable;
protected boolean mutableContent;
protected String priority;

public FCMMessage(Notification notification, boolean contentAvailable, String priority, String to) {
public FCMMessage(Notification notification, boolean contentAvailable, boolean mutableContent, String priority, String to) {
super(to);
this.notification = notification;
this.contentAvailable = contentAvailable;
this.mutableContent = mutableContent;
this.priority = priority;
}

Expand All @@ -40,6 +44,7 @@ public void setNotification(Notification notification) {
this.notification = notification;
}

@JsonProperty("content_available")
public boolean getContentAvailable() {
return contentAvailable;
}
Expand All @@ -48,6 +53,15 @@ public void setContentAvailable(boolean contentAvailable) {
this.contentAvailable = contentAvailable;
}

@JsonProperty("mutable_content")
public boolean getMutableContent() {
return mutableContent;
}

public void setMutableContent(boolean mutableContent) {
this.mutableContent = mutableContent;
}

public String getPriority() {
return priority;
}
Expand All @@ -61,6 +75,7 @@ public String toString() {
return getClass().getSimpleName() + "{" +
"notification=" + notification +
", contentAvailable=" + contentAvailable +
", mutableContent=" + mutableContent +
", priority='" + priority + '\'' +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
public class Notification {

protected String body;
protected boolean mutableContent;
protected String clickAction = "openremoteNotification";

public Notification(String body, boolean mutableContent) {
public Notification(String body) {
super();
this.body = body;
this.mutableContent = mutableContent;
}

public String getBody() {
Expand All @@ -41,15 +39,6 @@ public void setBody(String body) {
this.body = body;
}

@JsonProperty("mutable-content")
public boolean getMutableContent() {
return mutableContent;
}

public void setMutableContent(boolean mutableContent) {
this.mutableContent = mutableContent;
}

public String getClickAction() {
return clickAction;
}
Expand All @@ -58,7 +47,6 @@ public String getClickAction() {
public String toString() {
return getClass().getSimpleName() + "{" +
"body='" + body + '\'' +
", mutable-content=" + mutableContent +
", clickAction='" + clickAction + '\'' +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ public void storeAndNotify(String userId, AlertNotification alertNotification) {
for (DeviceNotificationToken notificationToken : allTokenForUser) {
try {
Invocation.Builder builder = firebaseTarget.request().header("Authorization", "key=" + fcmKey);
Notification notification = new Notification("_", true);
Notification notification = new Notification("_");

FCMBaseMessage message;
if ("ANDROID".equals(notificationToken.getDeviceType())) {
message = new FCMBaseMessage(notificationToken.getToken());
} else {
message = new FCMMessage(notification, true, "high", notificationToken.getToken());
message = new FCMMessage(notification, true, true, "high", notificationToken.getToken());
}
LOG.fine("Sending notification message to device of user '" + userId + "': " + message);
Response response = builder.post(Entity.entity(message, "application/json"));
Expand Down

0 comments on commit a904b76

Please sign in to comment.