Skip to content

Commit

Permalink
Merge pull request #5 from filipmaelbrancke/master
Browse files Browse the repository at this point in the history
Priority support
  • Loading branch information
filipmaelbrancke committed Jan 29, 2016
2 parents a7240d3 + 863366d commit 15a4c2f
Show file tree
Hide file tree
Showing 9 changed files with 1,026 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>be.appfoundry.promtius</groupId>
<artifactId>promtius-parent</artifactId>
<version>2.2</version>
<version>3.0</version>
<packaging>pom</packaging>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion promtius-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>be.appfoundry.promtius</groupId>
<artifactId>promtius-parent</artifactId>
<version>2.2</version>
<version>3.0</version>
</parent>

<artifactId>promtius-api</artifactId>
Expand Down
26 changes: 22 additions & 4 deletions promtius-api/src/main/java/be/appfoundry/promtius/PushPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ public class PushPayload {

public static final String DEFAULT_SOUND_VALUE = "default";
public static final String DEFAULT_DISCRIMINATOR_VALUE = "discriminator";
public static final PushPriority DEFAULT_PUSHPRIORITY_VALUE = PushPriority.NORMAL;
private String message;
private String sound;
private String discriminator;
private Optional<Map<String, ?>> customFields;
private Optional<Integer> timeToLive;
private PushPriority pushPriority;

/**
* @deprecated use the {@link be.appfoundry.promtius.PushPayload.Builder} to create new instances instead!
* Push priority.
* GCM documentation => https://developers.google.com/cloud-messaging/http-server-ref
* APNS documentation => https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Appendixes/BinaryProviderAPI.html#//apple_ref/doc/uid/TP40008194-CH106-SW5
*/
@Deprecated
public PushPayload(final String message) {
this.message = message;
public enum PushPriority {
NORMAL,
HIGH
}

private PushPayload() {
Expand Down Expand Up @@ -64,12 +68,20 @@ public String getDiscriminator() {
return discriminator;
}

/**
* The priority to be used for this message by the providers.
*/
public PushPriority getPushPriority() {
return pushPriority;
}

public static class Builder {
private String message;
private Optional<String> sound = Optional.absent();
private Optional<Integer> timeToLive = Optional.absent();
private Optional<Map<String, ?>> customFields = Optional.absent();
private Optional<String> discriminator = Optional.absent();
private Optional<PushPriority> pushPriority = Optional.absent();

public Builder withMessage(final String message) {
this.message = message;
Expand Down Expand Up @@ -97,6 +109,11 @@ public Builder withDiscriminator(final String discriminator) {
return this;
}

public Builder withPushPriority(final PushPriority pushPriority) {
this.pushPriority = Optional.of(pushPriority);
return this;
}

public PushPayload build() {
Preconditions.checkState(message != null);
PushPayload pushPayload = new PushPayload();
Expand All @@ -105,6 +122,7 @@ public PushPayload build() {
pushPayload.timeToLive = this.timeToLive;
pushPayload.customFields = this.customFields;
pushPayload.discriminator = this.discriminator.or(DEFAULT_DISCRIMINATOR_VALUE);
pushPayload.pushPriority = this.pushPriority.or(DEFAULT_PUSHPRIORITY_VALUE);
return pushPayload;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,15 @@ public void testCanBuildWithDiscriminator() throws Exception {
public void testCanBuildWithoutDiscriminator() throws Exception {
assertThat(payload.getDiscriminator(), is(equalTo(PushPayload.DEFAULT_DISCRIMINATOR_VALUE)));
}

@Test
public void testCanBuildWithPushPriority() throws Exception {
payload = validBuilder.withPushPriority(PushPayload.PushPriority.HIGH).build();
assertThat(payload.getPushPriority(), is(PushPayload.PushPriority.HIGH));
}

@Test
public void testCanBuildWithoutPushPriority() throws Exception {
assertThat(payload.getPushPriority(), is(PushPayload.PushPriority.NORMAL));
}
}
2 changes: 1 addition & 1 deletion promtius-apns/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>be.appfoundry.promtius</groupId>
<artifactId>promtius-parent</artifactId>
<version>2.2</version>
<version>3.0</version>
</parent>

<artifactId>promtius-apns</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion promtius-gcm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>be.appfoundry.promtius</groupId>
<artifactId>promtius-parent</artifactId>
<version>2.2</version>
<version>3.0</version>
</parent>

<artifactId>promtius-gcm</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import be.appfoundry.custom.google.android.gcm.server.Constants;
import be.appfoundry.custom.google.android.gcm.server.Message;
import be.appfoundry.custom.google.android.gcm.server.Message.Priority;
import be.appfoundry.custom.google.android.gcm.server.MulticastResult;
import be.appfoundry.custom.google.android.gcm.server.Result;
import be.appfoundry.promtius.ClientToken;
import be.appfoundry.promtius.ClientTokenFactory;
import be.appfoundry.promtius.ClientTokenService;
import be.appfoundry.promtius.PushPayload;
import be.appfoundry.promtius.PushPayload.PushPriority;
import be.appfoundry.promtius.Pusher;
import be.appfoundry.promtius.exception.PushFailedException;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -62,7 +64,8 @@ public void sendPush(final PushPayload payload, final Collection<G> groups) {
}

private void pushPayloadToClientsIdentifiedByTokens(final PushPayload payload, final List<CT> tokens) {
Message.Builder builder = new Message.Builder().addData("message", payload.getMessage()).addData("sound", payload.getSound()).collapseKey(payload.getDiscriminator());
final Priority gcmPriority = (payload.getPushPriority().equals(PushPriority.NORMAL)) ? Priority.NORMAL : Priority.HIGH;
Message.Builder builder = new Message.Builder().addData("message", payload.getMessage()).addData("sound", payload.getSound()).collapseKey(payload.getDiscriminator()).priority(gcmPriority);
if (payload.getCustomFields().isPresent()) {
Map<String, ?> customFields = payload.getCustomFields().get();
builder.addData("data", customFields);
Expand Down
Loading

0 comments on commit 15a4c2f

Please sign in to comment.