feat: Add ThreadID for apns (#326)

This commit is contained in:
Bo-Yi Wu 2018-01-05 17:08:43 +08:00 committed by GitHub
parent 6540d16e3e
commit 230cfb23fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 0 deletions

View File

@ -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"`

View File

@ -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)
}

View File

@ -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))