Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR #173 : add subtitle for ApsAlert #191

Merged
merged 4 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions messaging/messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
54 changes: 38 additions & 16 deletions messaging/messaging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
Expand All @@ -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",
},
},
},
Expand Down Expand Up @@ -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{
Expand Down
3 changes: 3 additions & 0 deletions messaging/messaging_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down