Fix HMS Push Notifications (#645)

This commit is contained in:
Hilário Coelho 2021-12-09 15:14:12 +00:00 committed by GitHub
parent bd920d34fb
commit 20e6566183
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 36 deletions

2
go.mod
View File

@ -38,3 +38,5 @@ require (
google.golang.org/grpc v1.36.1 google.golang.org/grpc v1.36.1
google.golang.org/protobuf v1.27.1 google.golang.org/protobuf v1.27.1
) )
replace github.com/msalihkarakasli/go-hms-push => github.com/spawn2kill/go-hms-push v0.0.0-20211125124117-e20af53b1304

4
go.sum
View File

@ -322,8 +322,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/msalihkarakasli/go-hms-push v0.0.0-20210731212030-00e7b986815b h1:GPoWsisltEZb9Itu1MMCXCUsYMKqC51nIG+3EqA3MdE=
github.com/msalihkarakasli/go-hms-push v0.0.0-20210731212030-00e7b986815b/go.mod h1:4X2lQHsWGt+e3uRK124A6ndq3IIVymTAzEI9A1kIQKc=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
@ -449,6 +447,8 @@ github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJ
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spawn2kill/go-hms-push v0.0.0-20211125124117-e20af53b1304 h1:NFx3I+/cQkqXlnrDzyOAXUDKWFjPQBcO0LSqowMn1Jo=
github.com/spawn2kill/go-hms-push v0.0.0-20211125124117-e20af53b1304/go.mod h1:4X2lQHsWGt+e3uRK124A6ndq3IIVymTAzEI9A1kIQKc=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=

View File

@ -9,7 +9,6 @@ import (
"github.com/appleboy/gorush/core" "github.com/appleboy/gorush/core"
"github.com/appleboy/gorush/logx" "github.com/appleboy/gorush/logx"
"github.com/appleboy/gorush/status" "github.com/appleboy/gorush/status"
c "github.com/msalihkarakasli/go-hms-push/push/config" c "github.com/msalihkarakasli/go-hms-push/push/config"
client "github.com/msalihkarakasli/go-hms-push/push/core" client "github.com/msalihkarakasli/go-hms-push/push/core"
"github.com/msalihkarakasli/go-hms-push/push/model" "github.com/msalihkarakasli/go-hms-push/push/model"
@ -21,7 +20,7 @@ var (
once sync.Once once sync.Once
) )
// GetPushClient use for create HMS Push // GetPushClient use for create HMS Push.
func GetPushClient(conf *c.Config) (*client.HMSClient, error) { func GetPushClient(conf *c.Config) (*client.HMSClient, error) {
once.Do(func() { once.Do(func() {
client, err := client.NewHttpClient(conf) client, err := client.NewHttpClient(conf)
@ -112,47 +111,43 @@ func GetHuaweiNotification(req *PushNotification) (*model.MessageRequest, error)
// Add data fields // Add data fields
if len(req.HuaweiData) > 0 { if len(req.HuaweiData) > 0 {
msgRequest.Message.Data = req.HuaweiData msgRequest.Message.Data = req.HuaweiData
} else { }
// Notification Message // Notification Message
msgRequest.Message.Android.Notification = model.GetDefaultAndroidNotification()
n := msgRequest.Message.Android.Notification
isNotificationSet := false
if req.HuaweiNotification != nil { if req.HuaweiNotification != nil {
isNotificationSet = true msgRequest.Message.Android.Notification = req.HuaweiNotification
n = req.HuaweiNotification
if n.ClickAction == nil { if msgRequest.Message.Android.Notification.ClickAction == nil {
n.ClickAction = model.GetDefaultClickAction() msgRequest.Message.Android.Notification.ClickAction = model.GetDefaultClickAction()
}
}
setDefaultAndroidNotification := func() {
if msgRequest.Message.Android == nil {
msgRequest.Message.Android.Notification = model.GetDefaultAndroidNotification()
} }
} }
if len(req.Message) > 0 { if len(req.Message) > 0 {
isNotificationSet = true setDefaultAndroidNotification()
n.Body = req.Message msgRequest.Message.Android.Notification.Body = req.Message
} }
if len(req.Title) > 0 { if len(req.Title) > 0 {
isNotificationSet = true setDefaultAndroidNotification()
n.Title = req.Title msgRequest.Message.Android.Notification.Title = req.Title
} }
if len(req.Image) > 0 { if len(req.Image) > 0 {
isNotificationSet = true setDefaultAndroidNotification()
n.Image = req.Image msgRequest.Message.Android.Notification.Image = req.Image
} }
if v, ok := req.Sound.(string); ok && len(v) > 0 { if v, ok := req.Sound.(string); ok && len(v) > 0 {
isNotificationSet = true setDefaultAndroidNotification()
n.Sound = v msgRequest.Message.Android.Notification.Sound = v
} else { } else if msgRequest.Message.Android.Notification != nil {
n.DefaultSound = true msgRequest.Message.Android.Notification.DefaultSound = true
}
if isNotificationSet {
msgRequest.Message.Android.Notification = n
}
} }
b, err := json.Marshal(msgRequest) b, err := json.Marshal(msgRequest)