Skip to content

Commit

Permalink
[SNS] Add APNs key 'mutable-content' (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
yukkobay authored and evalphobia committed Dec 27, 2018
1 parent d5f9cb2 commit 89ac56d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 7 additions & 0 deletions sns/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const (
apnsKeySound = "sound"
apnsKeyCategory = "category"
apnsKeyBadge = "badge"
apnsKeyMutableContent = "mutable-content"
)

const fcmPriorityHigh = "high"
Expand Down Expand Up @@ -49,6 +50,10 @@ func composeMessageAPNS(msg string, opt map[string]interface{}) (payload string,
aps[apnsKeyBadge] = v
}

if v, ok := opt[apnsKeyMutableContent]; ok {
aps[apnsKeyMutableContent] = v
}

message := make(map[string]interface{})
message["aps"] = aps
for k, v := range opt {
Expand All @@ -59,6 +64,8 @@ func composeMessageAPNS(msg string, opt map[string]interface{}) (payload string,
continue
case apnsKeyBadge:
continue
case apnsKeyMutableContent:
continue
default:
message[k] = v
}
Expand Down
11 changes: 9 additions & 2 deletions sns/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,22 @@ func TestComposeMessageAPNS(t *testing.T) {
assert.NoError(err)
assert.Equal(`{"aps":{"alert":"test","badge":5,"sound":"default"}}`, msg)

delete(opt, "badge")
opt["mutable-content"] = 1
msg, err = composeMessageAPNS("test", opt)
assert.NoError(err)
assert.Equal(`{"aps":{"alert":"test","mutable-content":1,"sound":"default"}}`, msg)

opt["sound"] = "jazz"
opt["category"] = "new_message"
opt["badge"] = 5
opt["mutable-content"] = 1
msg, err = composeMessageAPNS("test", opt)
assert.NoError(err)
assert.Equal(`{"aps":{"alert":"test","badge":5,"category":"new_message","sound":"jazz"}}`, msg)
assert.Equal(`{"aps":{"alert":"test","badge":5,"category":"new_message","mutable-content":1,"sound":"jazz"}}`, msg)

opt["x-option"] = "foo"
msg, err = composeMessageAPNS("test", opt)
assert.NoError(err)
assert.Equal(`{"aps":{"alert":"test","badge":5,"category":"new_message","sound":"jazz"},"x-option":"foo"}`, msg)
assert.Equal(`{"aps":{"alert":"test","badge":5,"category":"new_message","mutable-content":1,"sound":"jazz"},"x-option":"foo"}`, msg)
}

0 comments on commit 89ac56d

Please sign in to comment.