feat(ios12): Add support for Summary arguments in notifications (#384)

* feat(ios12): Add support for Summary arguments in notifications

* feat: upgrade go module
This commit is contained in:
Bo-Yi Wu 2018-11-20 11:02:26 +08:00 committed by GitHub
parent 49a81edbd0
commit 375eec1d90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 99 additions and 32 deletions

2
go.mod
View File

@ -38,7 +38,7 @@ require (
github.com/prometheus/client_model v0.0.0-20170216185247-6f3806018612 // indirect
github.com/prometheus/common v0.0.0-20170218233558-3007b6072c17 // indirect
github.com/prometheus/procfs v0.0.0-20170216223256-a1dba9ce8bae // indirect
github.com/sideshow/apns2 v0.0.0-20180827055107-3c5d4af1700e
github.com/sideshow/apns2 v0.0.0-20181014012405-060d44b53d05
github.com/sirupsen/logrus v0.0.0-20170620144510-3d4380f53a34
github.com/spf13/afero v0.0.0-20171021110813-5660eeed305f // indirect
github.com/spf13/cast v1.1.0 // indirect

2
go.sum
View File

@ -74,6 +74,8 @@ github.com/prometheus/procfs v0.0.0-20170216223256-a1dba9ce8bae h1:4W6eGKy6DVCKy
github.com/prometheus/procfs v0.0.0-20170216223256-a1dba9ce8bae/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/sideshow/apns2 v0.0.0-20180827055107-3c5d4af1700e h1:L+MeVX9/PAI/RJkx5YSlwgYtIMNIF6uLb4SVoZsXgLU=
github.com/sideshow/apns2 v0.0.0-20180827055107-3c5d4af1700e/go.mod h1:f7dArLPLbiZ3qPdzzrZXdCSlMp8FD0p6z7tHssDOLvk=
github.com/sideshow/apns2 v0.0.0-20181014012405-060d44b53d05 h1:3M+RJyiSlS8LumIYw9HbwwhKMQzJZ1HzTbU3FVmXy8o=
github.com/sideshow/apns2 v0.0.0-20181014012405-060d44b53d05/go.mod h1:f7dArLPLbiZ3qPdzzrZXdCSlMp8FD0p6z7tHssDOLvk=
github.com/sirupsen/logrus v0.0.0-20170620144510-3d4380f53a34 h1:kVLTAexkb0RpvzqHGdmxz80/bPLGuZn4qnUR0a4sW9Y=
github.com/sirupsen/logrus v0.0.0-20170620144510-3d4380f53a34/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
github.com/spf13/afero v0.0.0-20171021110813-5660eeed305f h1:+Dx5AA/mr18sj78olfUUNWiBBH18xbGhdXiOnLoKnzY=

View File

@ -40,6 +40,8 @@ type Alert struct {
Subtitle string `json:"subtitle,omitempty"`
TitleLocArgs []string `json:"title-loc-args,omitempty"`
TitleLocKey string `json:"title-loc-key,omitempty"`
SummaryArg string `json:"summary-arg,omitempty"`
SummaryArgCount int `json:"summary-arg-count,omitempty"`
}
// RequestPush support multiple notification request.

View File

@ -148,11 +148,18 @@ func iosAlertDictionary(payload *payload.Payload, req PushNotification) *payload
}
// General
if len(req.Category) > 0 {
payload.Category(req.Category)
}
if len(req.Alert.SummaryArg) > 0 {
payload.AlertSummaryArg(req.Alert.SummaryArg)
}
if req.Alert.SummaryArgCount > 0 {
payload.AlertSummaryArgCount(req.Alert.SummaryArgCount)
}
return payload
}

View File

@ -157,6 +157,38 @@ func TestIOSSoundAndVolume(t *testing.T) {
assert.Equal(t, int64(1), soundCritical)
}
func TestIOSSummaryArg(t *testing.T) {
var dat map[string]interface{}
test := "test"
message := "Welcome notification Server"
req := PushNotification{
ApnsID: test,
Topic: test,
Priority: "normal",
Message: message,
Alert: Alert{
SummaryArg: "test",
SummaryArgCount: 3,
},
}
notification := GetIOSNotification(req)
dump, _ := json.Marshal(notification.Payload)
data := []byte(string(dump))
if err := json.Unmarshal(data, &dat); err != nil {
panic(err)
}
assert.Equal(t, test, notification.ApnsID)
assert.Equal(t, test, notification.Topic)
assert.Equal(t, ApnsPriorityLow, notification.Priority)
assert.Equal(t, "test", dat["aps"].(map[string]interface{})["alert"].(map[string]interface{})["summary-arg"])
assert.Equal(t, float64(3), dat["aps"].(map[string]interface{})["alert"].(map[string]interface{})["summary-arg-count"])
}
// Silent Notification which payloads aps dictionary must not contain the alert, sound, or badge keys.
// ref: https://goo.gl/m9xyqG
func TestSendZeroValueForBadgeKey(t *testing.T) {

View File

@ -32,6 +32,8 @@ type alert struct {
Subtitle string `json:"subtitle,omitempty"`
TitleLocArgs []string `json:"title-loc-args,omitempty"`
TitleLocKey string `json:"title-loc-key,omitempty"`
SummaryArg string `json:"summary-arg,omitempty"`
SummaryArgCount int `json:"summary-arg-count,omitempty"`
}
type sound struct {
@ -235,13 +237,35 @@ func (p *Payload) AlertActionLocKey(key string) *Payload {
return p
}
// AlertSummaryArg sets the aps alert summary arg key on the payload.
// This is the string that is used as a key to fill in an argument
// at the bottom of a notification to provide more context, such as
// a name associated with the sender of the notification.
//
// {"aps":{"alert":{"summary-arg":key}}}
func (p *Payload) AlertSummaryArg(key string) *Payload {
p.aps().alert().SummaryArg = key
return p
}
// AlertSummaryArgCount sets the aps alert summary arg count key on the payload.
// This integer sets a custom "weight" on the notification, effectively
// allowing a notification to be viewed internally as two. For example if
// a notification encompasses 3 messages, you can set it to 3.
//
// {"aps":{"alert":{"summary-arg-count":key}}}
func (p *Payload) AlertSummaryArgCount(key int) *Payload {
p.aps().alert().SummaryArgCount = key
return p
}
// General
// Category sets the aps category on the payload.
// This is a string value that represents the identifier property of the
// UIMutableUserNotificationCategory object you created to define custom actions.
//
// {"aps":{"alert":{"category":category}}}
// {"aps":{"category":category}}
func (p *Payload) Category(category string) *Payload {
p.aps().Category = category
return p

18
vendor/vendor.json vendored
View File

@ -449,22 +449,22 @@
{
"checksumSHA1": "DL5vX9aOefzIAxMDdaQBtgRdR0Y=",
"path": "github.com/sideshow/apns2",
"revision": "3c5d4af1700ed9111ecb16a9a99a92a00c8b2f27",
"revisionTime": "2018-08-27T05:51:07Z",
"version": "master",
"versionExact": "master"
"revision": "5c6f7afc0242dbeab1c0b26a1efd761a67228004",
"revisionTime": "2018-10-12T08:22:23Z",
"version": "v0.15",
"versionExact": "v0.15"
},
{
"checksumSHA1": "EHOwwdWPJGt1vNVeJxyRDRHBhl8=",
"path": "github.com/sideshow/apns2/certificate",
"revision": "c6554aff77e6e5580dec977c8c33cc238f329ab0",
"revisionTime": "2018-04-13T21:53:35Z"
"revision": "060d44b53d05502e715958efde28063cd0746dba",
"revisionTime": "2018-10-14T01:24:05Z"
},
{
"checksumSHA1": "36bPwB1aiQCxfmdwfgYmI89I9nI=",
"checksumSHA1": "uwySZ0Z4LZ+9PIYqg7twpCQxv+I=",
"path": "github.com/sideshow/apns2/payload",
"revision": "3c5d4af1700ed9111ecb16a9a99a92a00c8b2f27",
"revisionTime": "2018-08-27T05:51:07Z"
"revision": "060d44b53d05502e715958efde28063cd0746dba",
"revisionTime": "2018-10-14T01:24:05Z"
},
{
"checksumSHA1": "nkQ/1JoIY4jh8XlI8LClfFVux9U=",