Skip to content

Commit 9f9a563

Browse files
chemidyhiranya911
authored andcommitted
FR #173 : add subtitle for ApsAlert (#191)
* add subtitle for ApsAlert * update changelog
1 parent f63ab44 commit 9f9a563

File tree

4 files changed

+54
-24
lines changed

4 files changed

+54
-24
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
- [added] `messaging.ApsAlert` type now supports subtitle in its payload.
4+
35
# v3.4.0
46

57
- [added] `firebase.App` now provides a new `DatabaseWithURL()` function

messaging/messaging.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,17 @@ func (a *Aps) MarshalJSON() ([]byte, error) {
399399
// See https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html
400400
// for supported fields.
401401
type ApsAlert struct {
402-
Title string `json:"title,omitempty"` // if specified, overrides the Title field of the Notification type
403-
Body string `json:"body,omitempty"` // if specified, overrides the Body field of the Notification type
404-
LocKey string `json:"loc-key,omitempty"`
405-
LocArgs []string `json:"loc-args,omitempty"`
406-
TitleLocKey string `json:"title-loc-key,omitempty"`
407-
TitleLocArgs []string `json:"title-loc-args,omitempty"`
408-
ActionLocKey string `json:"action-loc-key,omitempty"`
409-
LaunchImage string `json:"launch-image,omitempty"`
402+
Title string `json:"title,omitempty"` // if specified, overrides the Title field of the Notification type
403+
SubTitle string `json:"subtitle,omitempty"`
404+
Body string `json:"body,omitempty"` // if specified, overrides the Body field of the Notification type
405+
LocKey string `json:"loc-key,omitempty"`
406+
LocArgs []string `json:"loc-args,omitempty"`
407+
TitleLocKey string `json:"title-loc-key,omitempty"`
408+
TitleLocArgs []string `json:"title-loc-args,omitempty"`
409+
SubTitleLocKey string `json:"subtitle-loc-key,omitempty"`
410+
SubTitleLocArgs []string `json:"subtitle-loc-args,omitempty"`
411+
ActionLocKey string `json:"action-loc-key,omitempty"`
412+
LaunchImage string `json:"launch-image,omitempty"`
410413
}
411414

412415
// ErrorInfo is a topic management error.

messaging/messaging_test.go

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,17 @@ var validMessages = []struct {
370370
Payload: &APNSPayload{
371371
Aps: &Aps{
372372
Alert: &ApsAlert{
373-
Title: "t",
374-
Body: "b",
375-
TitleLocKey: "tlk",
376-
TitleLocArgs: []string{"t1", "t2"},
377-
LocKey: "blk",
378-
LocArgs: []string{"b1", "b2"},
379-
ActionLocKey: "alk",
380-
LaunchImage: "li",
373+
Title: "t",
374+
SubTitle: "st",
375+
Body: "b",
376+
TitleLocKey: "tlk",
377+
TitleLocArgs: []string{"t1", "t2"},
378+
SubTitleLocKey: "stlk",
379+
SubTitleLocArgs: []string{"t1", "t2"},
380+
LocKey: "blk",
381+
LocArgs: []string{"b1", "b2"},
382+
ActionLocKey: "alk",
383+
LaunchImage: "li",
381384
},
382385
},
383386
},
@@ -389,14 +392,17 @@ var validMessages = []struct {
389392
"payload": map[string]interface{}{
390393
"aps": map[string]interface{}{
391394
"alert": map[string]interface{}{
392-
"title": "t",
393-
"body": "b",
394-
"title-loc-key": "tlk",
395-
"title-loc-args": []interface{}{"t1", "t2"},
396-
"loc-key": "blk",
397-
"loc-args": []interface{}{"b1", "b2"},
398-
"action-loc-key": "alk",
399-
"launch-image": "li",
395+
"title": "t",
396+
"subtitle": "st",
397+
"body": "b",
398+
"title-loc-key": "tlk",
399+
"title-loc-args": []interface{}{"t1", "t2"},
400+
"subtitle-loc-key": "stlk",
401+
"subtitle-loc-args": []interface{}{"t1", "t2"},
402+
"loc-key": "blk",
403+
"loc-args": []interface{}{"b1", "b2"},
404+
"action-loc-key": "alk",
405+
"launch-image": "li",
400406
},
401407
},
402408
},
@@ -557,6 +563,22 @@ var invalidMessages = []struct {
557563
},
558564
want: "titleLocKey is required when specifying titleLocArgs",
559565
},
566+
{
567+
name: "InvalidAPNSSubTitleLocArgs",
568+
req: &Message{
569+
APNS: &APNSConfig{
570+
Payload: &APNSPayload{
571+
Aps: &Aps{
572+
Alert: &ApsAlert{
573+
SubTitleLocArgs: []string{"a1"},
574+
},
575+
},
576+
},
577+
},
578+
Topic: "topic",
579+
},
580+
want: "subtitleLocKey is required when specifying subtitleLocArgs",
581+
},
560582
{
561583
name: "InvalidAPNSLocArgs",
562584
req: &Message{

messaging/messaging_utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ func validateApsAlert(alert *ApsAlert) error {
126126
if len(alert.TitleLocArgs) > 0 && alert.TitleLocKey == "" {
127127
return fmt.Errorf("titleLocKey is required when specifying titleLocArgs")
128128
}
129+
if len(alert.SubTitleLocArgs) > 0 && alert.SubTitleLocKey == "" {
130+
return fmt.Errorf("subtitleLocKey is required when specifying subtitleLocArgs")
131+
}
129132
if len(alert.LocArgs) > 0 && alert.LocKey == "" {
130133
return fmt.Errorf("locKey is required when specifying locArgs")
131134
}

0 commit comments

Comments
 (0)