Skip to content

Commit

Permalink
added possibility to set category and sound on notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
bkuss committed Feb 29, 2016
1 parent cbde08f commit 449f537
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func newSubscribeDeviceRequestPayload(proto, token, lang string) io.Reader {
return bytes.NewBufferString(data.Encode())
}

func newNotifyPushNotificationRequestPayload(msg, title string, localizedMsg, data map[string]string, incrementBadge bool) io.Reader {
func newNotifyPushNotificationRequestPayload(msg, title string, localizedMsg, data map[string]string, incrementBadge bool, category string, sound string) io.Reader {
d := url.Values{}
if msg != "" {
d.Set("msg", msg)
Expand All @@ -50,7 +50,13 @@ func newNotifyPushNotificationRequestPayload(msg, title string, localizedMsg, da
for lang, localizedMsg := range localizedMsg {
d.Set("msg."+lang, localizedMsg)
}
d.Set("sound", "default")
if sound == "" {
sound = "default"
}
d.Set("sound", sound)
if category != "" {
d.Set("category", category)
}

for key, value := range data {
d.Set("data."+key, value)
Expand Down
8 changes: 4 additions & 4 deletions v1_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ func (this *V1) GetDeviceEvents(deviceId string) ([]EventSubscription, error) {
* Notifies all subscribers which are subscribed to the given language and sends them the given
* message and data.
*/
func (this *V1) NotifyDevices(event, lang, msg, title string, data map[string]string, incrementBadge bool) error {
func (this *V1) NotifyDevices(event, lang, msg, title string, data map[string]string, incrementBadge bool, category string, sound string) error {
localizedMsg := map[string]string{}
localizedMsg[lang] = msg
return this.NotifyDevicesLocalized(event, "", title, localizedMsg, data, incrementBadge)
return this.NotifyDevicesLocalized(event, "", title, localizedMsg, data, incrementBadge, category, sound)
}

/**
Expand All @@ -206,8 +206,8 @@ func (this *V1) NotifyDevices(event, lang, msg, title string, data map[string]st
* If still no message is found, the subscriber is _not_ notified. To send a message only to subscribers
* with a certain locale, leave the `msg` empty.
*/
func (this *V1) NotifyDevicesLocalized(event, msg, title string, localizedMsg, data map[string]string, incrementBadge bool) error {
requestPayload := newNotifyPushNotificationRequestPayload(msg, title, localizedMsg, data, incrementBadge)
func (this *V1) NotifyDevicesLocalized(event, msg, title string, localizedMsg, data map[string]string, incrementBadge bool, category string, sound string) error {
requestPayload := newNotifyPushNotificationRequestPayload(msg, title, localizedMsg, data, incrementBadge, category, sound)
path := "/event/" + event
code, body, postErr := this.request.post(path, "application/x-www-form-urlencoded", requestPayload)
if postErr != nil {
Expand Down

0 comments on commit 449f537

Please sign in to comment.