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

Commit 75d85f3

Browse files
timakinnathany
authored andcommitted
Support for grouping notifications with thread-id (#95)
* add: support for grouping notifications with thread-id * fix: indent
1 parent d71a6d2 commit 75d85f3

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

payload/aps.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ type APS struct {
2929

3030
// Mutable is used for Service Extensions introduced in iOS 10.
3131
MutableContent bool
32+
33+
// Thread identifier to create notification groups in iOS 12 or newer.
34+
ThreadID string
3235
}
3336

3437
// Alert dictionary.
@@ -93,6 +96,9 @@ func (a *APS) Map() map[string]interface{} {
9396
if a.MutableContent {
9497
aps["mutable-content"] = 1
9598
}
99+
if a.ThreadID != "" {
100+
aps["thread-id"] = a.ThreadID
101+
}
96102

97103
// wrap in "aps" to form the final payload
98104
return map[string]interface{}{"aps": aps}

payload/aps_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ func TestPayload(t *testing.T) {
9191
},
9292
[]byte(`{"aps":{"alert":"Change is coming","mutable-content":1}}`),
9393
},
94+
{
95+
payload.APS{
96+
Alert: payload.Alert{Body: "Grouped notification"},
97+
ThreadID: "thread-id-1",
98+
},
99+
[]byte(`{"aps":{"alert":"Grouped notification","thread-id":"thread-id-1"}}`),
100+
},
94101
}
95102

96103
for _, tt := range tests {

0 commit comments

Comments
 (0)