Skip to content

Commit

Permalink
Fix image fcm (#454)
Browse files Browse the repository at this point in the history
* allow sending data ONLY notifications for FCM notifications

* fix tests to pass

* support image parameter used for FCM

* remove unused import

* read apns payload on fcm notifications

* update go-fcm to 0.1.5
  • Loading branch information
SebastienMelki authored Feb 7, 2020
1 parent c379630 commit 3556bfd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/apex/gateway v1.1.1
github.com/appleboy/com v0.0.2
github.com/appleboy/gin-status-api v1.1.0
github.com/appleboy/go-fcm v0.1.4
github.com/appleboy/go-fcm v0.1.5
github.com/appleboy/gofight/v2 v2.1.2
github.com/asdine/storm v2.1.2+incompatible
github.com/aws/aws-lambda-go v1.13.3 // indirect
Expand Down Expand Up @@ -55,4 +55,5 @@ require (
gopkg.in/go-playground/validator.v9 v9.30.2 // indirect
gopkg.in/redis.v5 v5.2.9
gopkg.in/yaml.v2 v2.2.7 // indirect
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc // indirect
)
2 changes: 2 additions & 0 deletions gorush/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type PushNotification struct {
Platform int `json:"platform" binding:"required"`
Message string `json:"message,omitempty"`
Title string `json:"title,omitempty"`
Image string `json:"image,omitempty"`
Priority string `json:"priority,omitempty"`
ContentAvailable bool `json:"content_available,omitempty"`
MutableContent bool `json:"mutable_content,omitempty"`
Expand Down Expand Up @@ -95,6 +96,7 @@ type PushNotification struct {
Development bool `json:"development,omitempty"`
SoundName string `json:"name,omitempty"`
SoundVolume float32 `json:"volume,omitempty"`
Apns D `json:"apns,omitempty"`
}

// WaitDone decrements the WaitGroup counter.
Expand Down
12 changes: 11 additions & 1 deletion gorush/notification_fcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"

fcm "github.com/appleboy/go-fcm"
"github.com/appleboy/go-fcm"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -72,11 +72,21 @@ func GetAndroidNotification(req PushNotification) *fcm.Message {
notification.Notification.Title = req.Title
}

if len(req.Image) > 0 {
notification.Notification.Image = req.Image
}

if v, ok := req.Sound.(string); ok && len(v) > 0 {
notification.Notification.Sound = v
}
}

// handle iOS apns in fcm

if len(req.Apns) > 0 {
notification.Apns = req.Apns
}

return notification
}

Expand Down

0 comments on commit 3556bfd

Please sign in to comment.