Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 11 additions & 3 deletions notify/notification_apns.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func iosAlertDictionary(payload *payload.Payload, req *PushNotification) *payloa
// GetIOSNotification use for define iOS notification.
// The iOS Notification Payload (Payload Key Reference)
// Ref: https://apple.co/2VtH6Iu
func GetIOSNotification(req *PushNotification) *apns2.Notification {
func GetIOSNotification(req *PushNotification) (*apns2.Notification, error) {
notification := &apns2.Notification{
ApnsID: req.ApnsID,
Topic: req.Topic,
Expand Down Expand Up @@ -368,7 +368,15 @@ func GetIOSNotification(req *PushNotification) *apns2.Notification {

notification.Payload = payload

return notification
jsonMarshall, err := json.Marshal(notification)
if err != nil {
logx.LogError.Error("Failed to marshal the default message! Error is " + err.Error())
return nil, err
}

logx.LogAccess.Debugf("Default message going to APNs is %s", string(jsonMarshall))

return notification, nil
}

func getApnsClient(cfg *config.ConfYaml, req *PushNotification) (client *apns2.Client) {
Expand Down Expand Up @@ -406,7 +414,7 @@ func PushToIOS(req *PushNotification, cfg *config.ConfYaml) (resp *ResponsePush,
Retry:
var newTokens []string

notification := GetIOSNotification(req)
notification, _ := GetIOSNotification(req)
Comment thread
keremoge marked this conversation as resolved.
Outdated
client := getApnsClient(cfg, req)

var wg sync.WaitGroup
Expand Down
28 changes: 14 additions & 14 deletions notify/notification_apns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestIOSNotificationStructure(t *testing.T) {
URLArgs: []string{"a", "b"},
}

notification := GetIOSNotification(req)
notification, _ := GetIOSNotification(req)
Comment thread
keremoge marked this conversation as resolved.
Outdated

dump, _ := json.Marshal(notification.Payload)
data := []byte(string(dump))
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestIOSSoundAndVolume(t *testing.T) {
},
}

notification := GetIOSNotification(req)
notification, _ := GetIOSNotification(req)

dump, _ := json.Marshal(notification.Payload)
data := []byte(string(dump))
Expand All @@ -163,7 +163,7 @@ func TestIOSSoundAndVolume(t *testing.T) {

req.SoundName = "foobar"
req.SoundVolume = 5.5
notification = GetIOSNotification(req)
notification, _ = GetIOSNotification(req)
dump, _ = json.Marshal(notification.Payload)
data = []byte(string(dump))

Expand All @@ -190,7 +190,7 @@ func TestIOSSoundAndVolume(t *testing.T) {
},
}

notification = GetIOSNotification(req)
notification, _ = GetIOSNotification(req)
dump, _ = json.Marshal(notification.Payload)
data = []byte(string(dump))

Expand All @@ -213,7 +213,7 @@ func TestIOSSoundAndVolume(t *testing.T) {
Sound: "default",
}

notification = GetIOSNotification(req)
notification, _ = GetIOSNotification(req)
dump, _ = json.Marshal(notification.Payload)
data = []byte(string(dump))

Expand Down Expand Up @@ -241,7 +241,7 @@ func TestIOSSummaryArg(t *testing.T) {
},
}

notification := GetIOSNotification(req)
notification, _ := GetIOSNotification(req)

dump, _ := json.Marshal(notification.Payload)
data := []byte(string(dump))
Expand Down Expand Up @@ -275,7 +275,7 @@ func TestSendZeroValueForBadgeKey(t *testing.T) {
ThreadID: test,
}

notification := GetIOSNotification(req)
notification, _ := GetIOSNotification(req)

dump, _ := json.Marshal(notification.Payload)
data := []byte(string(dump))
Expand Down Expand Up @@ -310,7 +310,7 @@ func TestSendZeroValueForBadgeKey(t *testing.T) {
expectBadge := 10
req.Badge = &expectBadge

notification = GetIOSNotification(req)
notification, _ = GetIOSNotification(req)

dump, _ = json.Marshal(notification.Payload)
data = []byte(string(dump))
Expand Down Expand Up @@ -345,7 +345,7 @@ func TestCheckSilentNotification(t *testing.T) {
ContentAvailable: true,
}

notification := GetIOSNotification(req)
notification, _ := GetIOSNotification(req)

dump, _ := json.Marshal(notification.Payload)
data := []byte(string(dump))
Expand Down Expand Up @@ -395,7 +395,7 @@ func TestAlertStringExample2ForIos(t *testing.T) {
},
}

notification := GetIOSNotification(req)
notification, _ := GetIOSNotification(req)

dump, _ := json.Marshal(notification.Payload)
data := []byte(string(dump))
Expand Down Expand Up @@ -437,7 +437,7 @@ func TestAlertStringExample3ForIos(t *testing.T) {
Sound: sound,
}

notification := GetIOSNotification(req)
notification, _ := GetIOSNotification(req)

dump, _ := json.Marshal(notification.Payload)
data := []byte(string(dump))
Expand Down Expand Up @@ -467,7 +467,7 @@ func TestMessageAndTitle(t *testing.T) {
ContentAvailable: true,
}

notification := GetIOSNotification(req)
notification, _ := GetIOSNotification(req)

dump, _ := json.Marshal(notification.Payload)
data := []byte(string(dump))
Expand All @@ -491,7 +491,7 @@ func TestMessageAndTitle(t *testing.T) {
messageOverride := "Welcome notification Server overridden"
req.Alert.Body = messageOverride

notification = GetIOSNotification(req)
notification, _ = GetIOSNotification(req)

dump, _ = json.Marshal(notification.Payload)
data = []byte(string(dump))
Expand Down Expand Up @@ -528,7 +528,7 @@ func TestIOSAlertNotificationStructure(t *testing.T) {
},
}

notification := GetIOSNotification(req)
notification, _ := GetIOSNotification(req)

dump, _ := json.Marshal(notification.Payload)
data := []byte(string(dump))
Expand Down
14 changes: 11 additions & 3 deletions notify/notification_fcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func InitFCMClient(cfg *config.ConfYaml, key string) (*fcm.Client, error) {
// GetAndroidNotification use for define Android notification.
// HTTP Connection Server Reference for Android
// https://firebase.google.com/docs/cloud-messaging/http-server-ref
func GetAndroidNotification(req *PushNotification) *fcm.Message {
func GetAndroidNotification(req *PushNotification) (*fcm.Message, error) {
notification := &fcm.Message{
To: req.To,
Condition: req.Condition,
Expand Down Expand Up @@ -101,7 +101,15 @@ func GetAndroidNotification(req *PushNotification) *fcm.Message {
notification.Apns = req.Apns
}

return notification
jsonMarshall, err := json.Marshal(notification)
if err != nil {
logx.LogError.Error("Failed to marshal the default message! Error is " + err.Error())
return nil, err
}

logx.LogAccess.Debugf("Default message going to FCM server is %s", string(jsonMarshall))

return notification, nil
}

// PushToAndroid provide send notification to Android server.
Expand All @@ -128,7 +136,7 @@ func PushToAndroid(req *PushNotification, cfg *config.ConfYaml) (resp *ResponseP
resp = &ResponsePush{}

Retry:
notification := GetAndroidNotification(req)
notification, _ := GetAndroidNotification(req)

if req.APIKey != "" {
client, err = InitFCMClient(cfg, req.APIKey)
Expand Down
4 changes: 2 additions & 2 deletions notify/notification_fcm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func TestAndroidNotificationStructure(t *testing.T) {
},
}

notification := GetAndroidNotification(req)
notification, _ := GetAndroidNotification(req)

assert.Equal(t, test, notification.To)
assert.Equal(t, "high", notification.Priority)
Expand All @@ -265,7 +265,7 @@ func TestAndroidNotificationStructure(t *testing.T) {
Body: "",
},
}
notification = GetAndroidNotification(req)
notification, _ = GetAndroidNotification(req)

assert.Equal(t, test, notification.To)
assert.Equal(t, "", notification.Notification.Body)
Expand Down
2 changes: 1 addition & 1 deletion notify/notification_hms.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func GetHuaweiNotification(req *PushNotification) (*model.MessageRequest, error)
return nil, err
}

logx.LogAccess.Debugf("Default message is %s", string(b))
logx.LogAccess.Debugf("Default message going to Huawei Push Server is %s", string(b))
return msgRequest, nil
}

Expand Down
6 changes: 2 additions & 4 deletions storage/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ func (s *Storage) Init() error {
})
}

if err := s.client.Ping(s.ctx).Err(); err != nil {
return err
}
err := s.client.Ping(s.ctx).Err()
Comment thread
keremoge marked this conversation as resolved.

return nil
return err
}

// Close the storage connection
Expand Down