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

[Important] allow sending data ONLY notifications for FCM notifications #453

Merged
merged 5 commits into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 9 additions & 9 deletions gorush/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ type PushNotification struct {
Retry int `json:"retry,omitempty"`

// Android
APIKey string `json:"api_key,omitempty"`
To string `json:"to,omitempty"`
CollapseKey string `json:"collapse_key,omitempty"`
DelayWhileIdle bool `json:"delay_while_idle,omitempty"`
TimeToLive *uint `json:"time_to_live,omitempty"`
RestrictedPackageName string `json:"restricted_package_name,omitempty"`
DryRun bool `json:"dry_run,omitempty"`
Condition string `json:"condition,omitempty"`
Notification fcm.Notification `json:"notification,omitempty"`
APIKey string `json:"api_key,omitempty"`
To string `json:"to,omitempty"`
CollapseKey string `json:"collapse_key,omitempty"`
DelayWhileIdle bool `json:"delay_while_idle,omitempty"`
TimeToLive *uint `json:"time_to_live,omitempty"`
RestrictedPackageName string `json:"restricted_package_name,omitempty"`
DryRun bool `json:"dry_run,omitempty"`
Condition string `json:"condition,omitempty"`
Notification *fcm.Notification `json:"notification,omitempty"`

// iOS
Expiration *int64 `json:"expiration,omitempty"`
Expand Down
22 changes: 12 additions & 10 deletions gorush/notification_fcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,21 @@ func GetAndroidNotification(req PushNotification) *fcm.Message {
}
}

notification.Notification = &req.Notification
notification.Notification = req.Notification

// Set request message if body is empty
if len(req.Message) > 0 {
notification.Notification.Body = req.Message
}
if req.Notification != nil {
// Set request message if body is empty
if len(req.Message) > 0 {
notification.Notification.Body = req.Message
}

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

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

return notification
Expand Down
6 changes: 5 additions & 1 deletion gorush/notification_fcm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,10 @@ func TestAndroidNotificationStructure(t *testing.T) {
"a": "1",
"b": 2,
},
Notification: fcm.Notification{
Notification: &fcm.Notification{
Color: test,
Tag: test,
Body: "",
},
}

Expand All @@ -263,6 +264,9 @@ func TestAndroidNotificationStructure(t *testing.T) {
req = PushNotification{
Tokens: []string{"a", "b"},
To: test,
Notification: &fcm.Notification{
Body: "",
},
}
notification = GetAndroidNotification(req)

Expand Down