Skip to content

Commit 5c6f7af

Browse files
tommy-muehlesideshow
authored andcommitted
Add support for Summary arguments in notifications for iOS 12 (#119)
* Add summary-arg
1 parent 3c5d4af commit 5c6f7af

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

payload/builder.go

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ type aps struct {
2222
}
2323

2424
type alert struct {
25-
Action string `json:"action,omitempty"`
26-
ActionLocKey string `json:"action-loc-key,omitempty"`
27-
Body string `json:"body,omitempty"`
28-
LaunchImage string `json:"launch-image,omitempty"`
29-
LocArgs []string `json:"loc-args,omitempty"`
30-
LocKey string `json:"loc-key,omitempty"`
31-
Title string `json:"title,omitempty"`
32-
Subtitle string `json:"subtitle,omitempty"`
33-
TitleLocArgs []string `json:"title-loc-args,omitempty"`
34-
TitleLocKey string `json:"title-loc-key,omitempty"`
25+
Action string `json:"action,omitempty"`
26+
ActionLocKey string `json:"action-loc-key,omitempty"`
27+
Body string `json:"body,omitempty"`
28+
LaunchImage string `json:"launch-image,omitempty"`
29+
LocArgs []string `json:"loc-args,omitempty"`
30+
LocKey string `json:"loc-key,omitempty"`
31+
Title string `json:"title,omitempty"`
32+
Subtitle string `json:"subtitle,omitempty"`
33+
TitleLocArgs []string `json:"title-loc-args,omitempty"`
34+
TitleLocKey string `json:"title-loc-key,omitempty"`
35+
SummaryArg string `json:"summary-arg,omitempty"`
36+
SummaryArgCount int `json:"summary-arg-count,omitempty"`
3537
}
3638

3739
type sound struct {
@@ -235,6 +237,28 @@ func (p *Payload) AlertActionLocKey(key string) *Payload {
235237
return p
236238
}
237239

240+
// SummaryArg sets the aps alert summary arg key on the payload.
241+
// This is the string that is used as a key to fill in an argument
242+
// at the bottom of a notification to provide more context, such as
243+
// a name associated with the sender of the notification.
244+
//
245+
// {"aps":{"alert":{"summary-arg":key}}}
246+
func (p *Payload) AlertSummaryArg(key string) *Payload {
247+
p.aps().alert().SummaryArg = key
248+
return p
249+
}
250+
251+
// SummaryArgCount sets the aps alert summary arg count key on the payload.
252+
// This integer sets a custom "weight" on the notification, effectively
253+
// allowing a notification to be viewed internally as two. For example if
254+
// a notification encompasses 3 messages, you can set it to 3.
255+
//
256+
// {"aps":{"alert":{"summary-arg-count":key}}}
257+
func (p *Payload) AlertSummaryArgCount(key int) *Payload {
258+
p.aps().alert().SummaryArgCount = key
259+
return p
260+
}
261+
238262
// General
239263

240264
// Category sets the aps category on the payload.

payload/builder_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ func TestSoundVolume(t *testing.T) {
176176
assert.Equal(t, `{"aps":{"sound":{"critical":1,"name":"default","volume":0.5}}}`, string(b))
177177
}
178178

179+
func TestAlertSummaryArg(t *testing.T) {
180+
payload := NewPayload().AlertSummaryArg("Robert")
181+
b, _ := json.Marshal(payload)
182+
assert.Equal(t, `{"aps":{"alert":{"summary-arg":"Robert"}}}`, string(b))
183+
}
184+
185+
func TestAlertSummaryArgCount(t *testing.T) {
186+
payload := NewPayload().AlertSummaryArgCount(3)
187+
b, _ := json.Marshal(payload)
188+
assert.Equal(t, `{"aps":{"alert":{"summary-arg-count":3}}}`, string(b))
189+
}
190+
179191
func TestCombined(t *testing.T) {
180192
payload := NewPayload().Alert("hello").Badge(1).Sound("Default.caf").Custom("key", "val")
181193
b, _ := json.Marshal(payload)

0 commit comments

Comments
 (0)