Skip to content

Commit

Permalink
add subtitle-loc-key and subtitle-loc-args in payload alert (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliach98 authored Aug 8, 2024
1 parent 79519b7 commit a0adba5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
24 changes: 24 additions & 0 deletions payload/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ type alert struct {
Subtitle string `json:"subtitle,omitempty"`
TitleLocArgs []string `json:"title-loc-args,omitempty"`
TitleLocKey string `json:"title-loc-key,omitempty"`
SubtitleLocArgs []string `json:"subtitle-loc-args,omitempty"`
SubtitleLocKey string `json:"subtitle-loc-key,omitempty"`
SummaryArg string `json:"summary-arg,omitempty"`
SummaryArgCount int `json:"summary-arg-count,omitempty"`
}
Expand Down Expand Up @@ -274,6 +276,28 @@ func (p *Payload) AlertSubtitle(subtitle string) *Payload {
return p
}

// AlertSubtitleLocKey sets the aps alert subtitle localization key on the payload.
// This is the key to a subtitle string in the Localizable.strings file for the
// current localization. See Localized Formatted Strings in Apple documentation
// for more information.
//
// {"aps":{"alert":{"subtitle-loc-key":key}}}
func (p *Payload) AlertSubtitleLocKey(key string) *Payload {
p.aps().alert().SubtitleLocKey = key
return p
}

// AlertSubtitleLocArgs sets the aps alert subtitle localization args on the payload.
// These are the variable string values to appear in place of the format
// specifiers in subtitle-loc-key. See Localized Formatted Strings in Apple
// documentation for more information.
//
// {"aps":{"alert":{"title-loc-args":args}}}
func (p *Payload) AlertSubtitleLocArgs(args []string) *Payload {
p.aps().alert().SubtitleLocArgs = args
return p
}

// AlertBody sets the aps alert body on the payload.
// This is the text of the alert message.
//
Expand Down
12 changes: 12 additions & 0 deletions payload/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ func TestAlertSubtitle(t *testing.T) {
assert.Equal(t, `{"aps":{"alert":{"subtitle":"hello"}}}`, string(b))
}

func TestAlertSubtitleLocKey(t *testing.T) {
payload := NewPayload().AlertSubtitleLocKey("Notification.Key.TestSubtitle")
b, _ := json.Marshal(payload)
assert.Equal(t, `{"aps":{"alert":{"subtitle-loc-key":"Notification.Key.TestSubtitle"}}}`, string(b))
}

func TestAlertSubtitleLocArgs(t *testing.T) {
payload := NewPayload().AlertSubtitleLocArgs([]string{"one", "two"})
b, _ := json.Marshal(payload)
assert.Equal(t, `{"aps":{"alert":{"subtitle-loc-args":["one","two"]}}}`, string(b))
}

func TestAlertBody(t *testing.T) {
payload := NewPayload().AlertBody("body")
b, _ := json.Marshal(payload)
Expand Down

0 comments on commit a0adba5

Please sign in to comment.