Repository: relayrides/pushy (java)

Issue:
Support for target-content-id key in aps dictionary.
Hi,

Are there any plans to support "target-content-id" key in aps dictionary.
This key is introduced in iOS 13.
This was announced in this [session.](https://developer.apple.com/videos/play/wwdc2019/259) [seek to 05:05 in video]
Documentation for this can be found [here.](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification#2943363)

Pull request description:
Add support for the `target-content-id` payload field
This adds support for setting the `target-content-id` field in push notification payloads and closes #716.

Patch:
diff --git a/pushy/src/main/java/com/turo/pushy/apns/util/ApnsPayloadBuilder.java b/pushy/src/main/java/com/turo/pushy/apns/util/ApnsPayloadBuilder.java
index f87a4116..5f4dc74b 100644
--- a/pushy/src/main/java/com/turo/pushy/apns/util/ApnsPayloadBuilder.java
+++ b/pushy/src/main/java/com/turo/pushy/apns/util/ApnsPayloadBuilder.java
@@ -67,6 +67,7 @@ public class ApnsPayloadBuilder {
     private boolean mutableContent = false;
 
     private String threadId = null;
+    private String targetContentId = null;
 
     private String summaryArgument = null;
     private Integer summaryArgumentCount = null;
@@ -85,6 +86,7 @@ public class ApnsPayloadBuilder {
     private static final String CONTENT_AVAILABLE_KEY = "content-available";
     private static final String MUTABLE_CONTENT_KEY = "mutable-content";
     private static final String THREAD_ID_KEY = "thread-id";
+    private static final String TARGET_CONTENT_ID_KEY = "target-content-id";
     private static final String SUMMARY_ARGUMENT_KEY = "summary-arg";
     private static final String SUMMARY_ARGUMENT_COUNT_KEY = "summary-arg-count";
     private static final String URL_ARGS_KEY = "url-args";
@@ -535,6 +537,21 @@ public class ApnsPayloadBuilder {
         return this;
     }
 
+    /**
+     * Sets the identifier of the window to be brought forward by this notification. By default, no target content ID
+     * is included.
+     *
+     * @param targetContentId the identifier of the window to be brought forward by this notification
+     *
+     * @return a reference to this payload builder
+     *
+     * @since 0.13.10
+     */
+    public ApnsPayloadBuilder setTargetContentId(final String targetContentId) {
+        this.targetContentId = targetContentId;
+        return this;
+    }
+
     /**
      * <p>Sets the summary argument for this notification. The summary argument is:</p>
      *
@@ -741,6 +758,10 @@ public class ApnsPayloadBuilder {
                 aps.put(THREAD_ID_KEY, this.threadId);
             }
 
+            if (this.targetContentId != null) {
+                aps.put(TARGET_CONTENT_ID_KEY, this.targetContentId);
+            }
+
             if (this.urlArguments != null) {
                 aps.put(URL_ARGS_KEY, this.urlArguments);
             }


Test patch:
diff --git a/pushy/src/test/java/com/turo/pushy/apns/util/ApnsPayloadBuilderTest.java b/pushy/src/test/java/com/turo/pushy/apns/util/ApnsPayloadBuilderTest.java
index faa2971b..d2d75bae 100644
--- a/pushy/src/test/java/com/turo/pushy/apns/util/ApnsPayloadBuilderTest.java
+++ b/pushy/src/test/java/com/turo/pushy/apns/util/ApnsPayloadBuilderTest.java
@@ -454,6 +454,16 @@ public class ApnsPayloadBuilderTest {
         assertEquals(threadId, aps.get("thread-id"));
     }
 
+    @Test
+    public void setTargetContentId() {
+        final String targetContentId = "example.window.id";
+
+        this.builder.setTargetContentId(targetContentId);
+
+        final Map<String, Object> aps = this.extractApsObjectFromPayloadString(this.builder.buildWithDefaultMaximumLength());
+        assertEquals(targetContentId, aps.get("target-content-id"));
+    }
+
     @Test
     public void testSetSummaryArgument() {
         final String summaryArgument = "This is a summary argument";