From bd6a6f7eba1515f2afff8cbc77be0bed3bf146d3 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Wed, 15 Nov 2017 10:12:09 -0600 Subject: [PATCH] Add CollapseID for ios notification. (#308) Signed-off-by: Bo-Yi Wu --- gorush/notification.go | 1 + gorush/notification_apns.go | 5 +++-- gorush/notification_apns_test.go | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/gorush/notification.go b/gorush/notification.go index 3f498d3..6993d37 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -76,6 +76,7 @@ type PushNotification struct { // iOS Expiration int64 `json:"expiration,omitempty"` ApnsID string `json:"apns_id,omitempty"` + CollapseID string `json:"collapse_id,omitempty"` Topic string `json:"topic,omitempty"` Badge *int `json:"badge,omitempty"` Category string `json:"category,omitempty"` diff --git a/gorush/notification_apns.go b/gorush/notification_apns.go index 93220fc..83ec8fb 100644 --- a/gorush/notification_apns.go +++ b/gorush/notification_apns.go @@ -125,8 +125,9 @@ func iosAlertDictionary(payload *payload.Payload, req PushNotification) *payload // ref: https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#//apple_ref/doc/uid/TP40008194-CH17-SW1 func GetIOSNotification(req PushNotification) *apns2.Notification { notification := &apns2.Notification{ - ApnsID: req.ApnsID, - Topic: req.Topic, + ApnsID: req.ApnsID, + Topic: req.Topic, + CollapseID: req.CollapseID, } if req.Expiration > 0 { diff --git a/gorush/notification_apns_test.go b/gorush/notification_apns_test.go index d73d127..071207a 100644 --- a/gorush/notification_apns_test.go +++ b/gorush/notification_apns_test.go @@ -180,6 +180,7 @@ func TestCheckSilentNotification(t *testing.T) { req := PushNotification{ ApnsID: test, Topic: test, + CollapseID: test, Priority: "normal", ContentAvailable: true, } @@ -194,6 +195,9 @@ func TestCheckSilentNotification(t *testing.T) { panic(err) } + assert.Equal(t, test, notification.CollapseID) + assert.Equal(t, test, notification.ApnsID) + assert.Equal(t, test, notification.Topic) assert.Nil(t, dat["aps"].(map[string]interface{})["alert"]) assert.Nil(t, dat["aps"].(map[string]interface{})["sound"]) assert.Nil(t, dat["aps"].(map[string]interface{})["badge"])