Fix HMS Push Notifications (#645)
This commit is contained in:
parent
bd920d34fb
commit
20e6566183
2
go.mod
2
go.mod
|
@ -38,3 +38,5 @@ require (
|
|||
google.golang.org/grpc v1.36.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
4
go.sum
|
@ -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 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
||||
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-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
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 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
|
||||
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/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
|
||||
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"github.com/appleboy/gorush/core"
|
||||
"github.com/appleboy/gorush/logx"
|
||||
"github.com/appleboy/gorush/status"
|
||||
|
||||
c "github.com/msalihkarakasli/go-hms-push/push/config"
|
||||
client "github.com/msalihkarakasli/go-hms-push/push/core"
|
||||
"github.com/msalihkarakasli/go-hms-push/push/model"
|
||||
|
@ -21,7 +20,7 @@ var (
|
|||
once sync.Once
|
||||
)
|
||||
|
||||
// GetPushClient use for create HMS Push
|
||||
// GetPushClient use for create HMS Push.
|
||||
func GetPushClient(conf *c.Config) (*client.HMSClient, error) {
|
||||
once.Do(func() {
|
||||
client, err := client.NewHttpClient(conf)
|
||||
|
@ -112,47 +111,43 @@ func GetHuaweiNotification(req *PushNotification) (*model.MessageRequest, error)
|
|||
// Add data fields
|
||||
if len(req.HuaweiData) > 0 {
|
||||
msgRequest.Message.Data = req.HuaweiData
|
||||
} else {
|
||||
// Notification Message
|
||||
msgRequest.Message.Android.Notification = model.GetDefaultAndroidNotification()
|
||||
}
|
||||
|
||||
n := msgRequest.Message.Android.Notification
|
||||
isNotificationSet := false
|
||||
// Notification Message
|
||||
if req.HuaweiNotification != nil {
|
||||
msgRequest.Message.Android.Notification = req.HuaweiNotification
|
||||
|
||||
if req.HuaweiNotification != nil {
|
||||
isNotificationSet = true
|
||||
n = req.HuaweiNotification
|
||||
|
||||
if n.ClickAction == nil {
|
||||
n.ClickAction = model.GetDefaultClickAction()
|
||||
}
|
||||
if msgRequest.Message.Android.Notification.ClickAction == nil {
|
||||
msgRequest.Message.Android.Notification.ClickAction = model.GetDefaultClickAction()
|
||||
}
|
||||
}
|
||||
|
||||
if len(req.Message) > 0 {
|
||||
isNotificationSet = true
|
||||
n.Body = req.Message
|
||||
setDefaultAndroidNotification := func() {
|
||||
if msgRequest.Message.Android == nil {
|
||||
msgRequest.Message.Android.Notification = model.GetDefaultAndroidNotification()
|
||||
}
|
||||
}
|
||||
|
||||
if len(req.Title) > 0 {
|
||||
isNotificationSet = true
|
||||
n.Title = req.Title
|
||||
}
|
||||
if len(req.Message) > 0 {
|
||||
setDefaultAndroidNotification()
|
||||
msgRequest.Message.Android.Notification.Body = req.Message
|
||||
}
|
||||
|
||||
if len(req.Image) > 0 {
|
||||
isNotificationSet = true
|
||||
n.Image = req.Image
|
||||
}
|
||||
if len(req.Title) > 0 {
|
||||
setDefaultAndroidNotification()
|
||||
msgRequest.Message.Android.Notification.Title = req.Title
|
||||
}
|
||||
|
||||
if v, ok := req.Sound.(string); ok && len(v) > 0 {
|
||||
isNotificationSet = true
|
||||
n.Sound = v
|
||||
} else {
|
||||
n.DefaultSound = true
|
||||
}
|
||||
if len(req.Image) > 0 {
|
||||
setDefaultAndroidNotification()
|
||||
msgRequest.Message.Android.Notification.Image = req.Image
|
||||
}
|
||||
|
||||
if isNotificationSet {
|
||||
msgRequest.Message.Android.Notification = n
|
||||
}
|
||||
if v, ok := req.Sound.(string); ok && len(v) > 0 {
|
||||
setDefaultAndroidNotification()
|
||||
msgRequest.Message.Android.Notification.Sound = v
|
||||
} else if msgRequest.Message.Android.Notification != nil {
|
||||
msgRequest.Message.Android.Notification.DefaultSound = true
|
||||
}
|
||||
|
||||
b, err := json.Marshal(msgRequest)
|
||||
|
|
Loading…
Reference in New Issue