Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Add more aps dictionary items
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Heid committed May 28, 2020
1 parent 404b010 commit 256962e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ This project is licensed under the LGPL License - see the [license](LICENSE) fil
### 2.4.2

* Logging improvements (replace string concatenation)
* Add more aps dictionary items: thread-id, category and target-content-id

### 2.4.1

Expand Down
30 changes: 30 additions & 0 deletions src/main/java/javapns/notification/PushNotificationPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,36 @@ public void addSound(String sound) {
put("sound", sound, this.apsDictionary, true);
}

/**
* Add an app-specific identifier for grouping related notifications.
*
* @param threadId the app-specific identifier for grouping related notifications
*/
public void addThreadId(String threadId) {
logger.debug("Adding thread id [{}]", threadId);
put("thread-id", threadId, this.apsDictionary, true);
}

/**
* Add a notification type
*
* @param category the notification type
*/
public void addCategory(String category) {
logger.debug("Adding category [{}]", category);
put("category", category, this.apsDictionary, true);
}

/**
* Add a identifier of the window brought forward
*
* @param targetContentId the notification type
*/
public void addTargetContentId(String targetContentId) {
logger.debug("Adding target content id [{}]", targetContentId);
put("target-content-id", targetContentId, this.apsDictionary, true);
}

/**
* Add a media attachment.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,38 @@ public void allowsToAddMediaAttachment() {
assertThat(payload.getString("my-attachment"), is("https://some.url.local/attachement"));

}

@Test
public void allowsToAddThreadId() {

pushNotificationPayload.addThreadId("myThreadId");

JSONObject payload = pushNotificationPayload.getPayload();
JSONObject aps = payload.getJSONObject("aps");
assertThat(aps.getString("thread-id"), is("myThreadId"));

}

@Test
public void allowsToAddCategory() {

pushNotificationPayload.addCategory("myCategory");

JSONObject payload = pushNotificationPayload.getPayload();
JSONObject aps = payload.getJSONObject("aps");
assertThat(aps.getString("category"), is("myCategory"));

}

@Test
public void allowsToTargetContentId() {

pushNotificationPayload.addTargetContentId("myTargetContentId");

JSONObject payload = pushNotificationPayload.getPayload();
JSONObject aps = payload.getJSONObject("aps");
assertThat(aps.getString("target-content-id"), is("myTargetContentId"));

}

}

0 comments on commit 256962e

Please sign in to comment.