From 230cfb23fa0d9e652903e15e272e05ba56cc6d49 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 5 Jan 2018 17:08:43 +0800 Subject: [PATCH] feat: Add ThreadID for apns (#326) --- gorush/notification.go | 1 + gorush/notification_apns.go | 4 ++++ gorush/notification_apns_test.go | 3 +++ 3 files changed, 8 insertions(+) diff --git a/gorush/notification.go b/gorush/notification.go index 6993d37..c9ad6f3 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -80,6 +80,7 @@ type PushNotification struct { Topic string `json:"topic,omitempty"` Badge *int `json:"badge,omitempty"` Category string `json:"category,omitempty"` + ThreadID string `json:"thread-id,omitempty"` URLArgs []string `json:"url-args,omitempty"` Alert Alert `json:"alert,omitempty"` MutableContent bool `json:"mutable-content,omitempty"` diff --git a/gorush/notification_apns.go b/gorush/notification_apns.go index 83ec8fb..4ed73be 100644 --- a/gorush/notification_apns.go +++ b/gorush/notification_apns.go @@ -166,6 +166,10 @@ func GetIOSNotification(req PushNotification) *apns2.Notification { payload.URLArgs(req.URLArgs) } + if len(req.ThreadID) > 0 { + payload.ThreadID(req.ThreadID) + } + for k, v := range req.Data { payload.Custom(k, v) } diff --git a/gorush/notification_apns_test.go b/gorush/notification_apns_test.go index 071207a..b18c940 100644 --- a/gorush/notification_apns_test.go +++ b/gorush/notification_apns_test.go @@ -115,6 +115,7 @@ func TestSendZeroValueForBadgeKey(t *testing.T) { Sound: test, ContentAvailable: true, MutableContent: true, + ThreadID: test, } notification := GetIOSNotification(req) @@ -130,6 +131,7 @@ func TestSendZeroValueForBadgeKey(t *testing.T) { alert, _ := jsonparser.GetString(data, "aps", "alert") badge, _ := jsonparser.GetInt(data, "aps", "badge") sound, _ := jsonparser.GetString(data, "aps", "sound") + threadID, _ := jsonparser.GetString(data, "aps", "thread-id") contentAvailable, _ := jsonparser.GetInt(data, "aps", "content-available") mutableContent, _ := jsonparser.GetInt(data, "aps", "mutable-content") @@ -143,6 +145,7 @@ func TestSendZeroValueForBadgeKey(t *testing.T) { assert.Equal(t, message, alert) assert.Equal(t, 0, int(badge)) assert.Equal(t, test, sound) + assert.Equal(t, test, threadID) assert.Equal(t, 1, int(contentAvailable)) assert.Equal(t, 1, int(mutableContent))