Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
Support for grouping notifications with thread-id (#95)
Browse files Browse the repository at this point in the history
* add: support for grouping notifications with thread-id

* fix: indent
  • Loading branch information
timakin authored and nathany committed Jan 21, 2019
1 parent d71a6d2 commit 75d85f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions payload/aps.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type APS struct {

// Mutable is used for Service Extensions introduced in iOS 10.
MutableContent bool

// Thread identifier to create notification groups in iOS 12 or newer.
ThreadID string
}

// Alert dictionary.
Expand Down Expand Up @@ -93,6 +96,9 @@ func (a *APS) Map() map[string]interface{} {
if a.MutableContent {
aps["mutable-content"] = 1
}
if a.ThreadID != "" {
aps["thread-id"] = a.ThreadID
}

// wrap in "aps" to form the final payload
return map[string]interface{}{"aps": aps}
Expand Down
7 changes: 7 additions & 0 deletions payload/aps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ func TestPayload(t *testing.T) {
},
[]byte(`{"aps":{"alert":"Change is coming","mutable-content":1}}`),
},
{
payload.APS{
Alert: payload.Alert{Body: "Grouped notification"},
ThreadID: "thread-id-1",
},
[]byte(`{"aps":{"alert":"Grouped notification","thread-id":"thread-id-1"}}`),
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 75d85f3

Please sign in to comment.