From 57aec470d3502309cb63ed90b1b9c836158580ed Mon Sep 17 00:00:00 2001 From: Cyrille Hemidy Date: Wed, 14 Nov 2018 09:15:31 +0100 Subject: [PATCH 1/2] add subtitle for ApsAlert --- messaging/messaging.go | 19 +++++++------ messaging/messaging_test.go | 54 +++++++++++++++++++++++++----------- messaging/messaging_utils.go | 3 ++ 3 files changed, 52 insertions(+), 24 deletions(-) diff --git a/messaging/messaging.go b/messaging/messaging.go index 8220d4a8..957ebb23 100644 --- a/messaging/messaging.go +++ b/messaging/messaging.go @@ -394,14 +394,17 @@ func (a *Aps) MarshalJSON() ([]byte, error) { // See https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html // for supported fields. type ApsAlert struct { - Title string `json:"title,omitempty"` // if specified, overrides the Title field of the Notification type - Body string `json:"body,omitempty"` // if specified, overrides the Body field of the Notification type - LocKey string `json:"loc-key,omitempty"` - LocArgs []string `json:"loc-args,omitempty"` - TitleLocKey string `json:"title-loc-key,omitempty"` - TitleLocArgs []string `json:"title-loc-args,omitempty"` - ActionLocKey string `json:"action-loc-key,omitempty"` - LaunchImage string `json:"launch-image,omitempty"` + Title string `json:"title,omitempty"` // if specified, overrides the Title field of the Notification type + SubTitle string `json:"subtitle,omitempty"` + Body string `json:"body,omitempty"` // if specified, overrides the Body field of the Notification type + LocKey string `json:"loc-key,omitempty"` + LocArgs []string `json:"loc-args,omitempty"` + TitleLocKey string `json:"title-loc-key,omitempty"` + TitleLocArgs []string `json:"title-loc-args,omitempty"` + SubTitleLocKey string `json:"subtitle-loc-key,omitempty"` + SubTitleLocArgs []string `json:"subtitle-loc-args,omitempty"` + ActionLocKey string `json:"action-loc-key,omitempty"` + LaunchImage string `json:"launch-image,omitempty"` } // ErrorInfo is a topic management error. diff --git a/messaging/messaging_test.go b/messaging/messaging_test.go index f71a1f73..637e69fe 100644 --- a/messaging/messaging_test.go +++ b/messaging/messaging_test.go @@ -365,14 +365,17 @@ var validMessages = []struct { Payload: &APNSPayload{ Aps: &Aps{ Alert: &ApsAlert{ - Title: "t", - Body: "b", - TitleLocKey: "tlk", - TitleLocArgs: []string{"t1", "t2"}, - LocKey: "blk", - LocArgs: []string{"b1", "b2"}, - ActionLocKey: "alk", - LaunchImage: "li", + Title: "t", + SubTitle: "st", + Body: "b", + TitleLocKey: "tlk", + TitleLocArgs: []string{"t1", "t2"}, + SubTitleLocKey: "stlk", + SubTitleLocArgs: []string{"t1", "t2"}, + LocKey: "blk", + LocArgs: []string{"b1", "b2"}, + ActionLocKey: "alk", + LaunchImage: "li", }, }, }, @@ -384,14 +387,17 @@ var validMessages = []struct { "payload": map[string]interface{}{ "aps": map[string]interface{}{ "alert": map[string]interface{}{ - "title": "t", - "body": "b", - "title-loc-key": "tlk", - "title-loc-args": []interface{}{"t1", "t2"}, - "loc-key": "blk", - "loc-args": []interface{}{"b1", "b2"}, - "action-loc-key": "alk", - "launch-image": "li", + "title": "t", + "subtitle": "st", + "body": "b", + "title-loc-key": "tlk", + "title-loc-args": []interface{}{"t1", "t2"}, + "subtitle-loc-key": "stlk", + "subtitle-loc-args": []interface{}{"t1", "t2"}, + "loc-key": "blk", + "loc-args": []interface{}{"b1", "b2"}, + "action-loc-key": "alk", + "launch-image": "li", }, }, }, @@ -552,6 +558,22 @@ var invalidMessages = []struct { }, want: "titleLocKey is required when specifying titleLocArgs", }, + { + name: "InvalidAPNSSubTitleLocArgs", + req: &Message{ + APNS: &APNSConfig{ + Payload: &APNSPayload{ + Aps: &Aps{ + Alert: &ApsAlert{ + SubTitleLocArgs: []string{"a1"}, + }, + }, + }, + }, + Topic: "topic", + }, + want: "subtitleLocKey is required when specifying subtitleLocArgs", + }, { name: "InvalidAPNSLocArgs", req: &Message{ diff --git a/messaging/messaging_utils.go b/messaging/messaging_utils.go index ed3ae838..c0f0c870 100644 --- a/messaging/messaging_utils.go +++ b/messaging/messaging_utils.go @@ -125,6 +125,9 @@ func validateApsAlert(alert *ApsAlert) error { if len(alert.TitleLocArgs) > 0 && alert.TitleLocKey == "" { return fmt.Errorf("titleLocKey is required when specifying titleLocArgs") } + if len(alert.SubTitleLocArgs) > 0 && alert.SubTitleLocKey == "" { + return fmt.Errorf("subtitleLocKey is required when specifying subtitleLocArgs") + } if len(alert.LocArgs) > 0 && alert.LocKey == "" { return fmt.Errorf("locKey is required when specifying locArgs") } From 416069bd0d9f263bb3493e9476f265541df62e6b Mon Sep 17 00:00:00 2001 From: Cyrille Hemidy Date: Wed, 14 Nov 2018 22:57:18 +0100 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b47918f..8e460d27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +- [added] `messaging.ApsAlert` type now supports subtitle in its payload. + # v3.4.0 - [added] `firebase.App` now provides a new `DatabaseWithURL()` function