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 diff --git a/messaging/messaging.go b/messaging/messaging.go index 5d18dc93..91bd7838 100644 --- a/messaging/messaging.go +++ b/messaging/messaging.go @@ -399,14 +399,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 55a6f4cd..bc8382ff 100644 --- a/messaging/messaging_test.go +++ b/messaging/messaging_test.go @@ -370,14 +370,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", }, }, }, @@ -389,14 +392,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", }, }, }, @@ -557,6 +563,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 9c7a99b7..d34aba79 100644 --- a/messaging/messaging_utils.go +++ b/messaging/messaging_utils.go @@ -126,6 +126,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") }