Skip to content

Commit 499e87c

Browse files
committed
Optimize push deletion logic
1 parent 647ad91 commit 499e87c

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

apns/apns.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ func (p PushMessage) IsEmptyAlert() bool {
3333
return p.Title == "" && p.Body == "" && p.Subtitle == ""
3434
}
3535

36-
// Check if it's an encrypted push notification
37-
func (p PushMessage) IsEncrypted() bool {
38-
return p.ExtParams["ciphertext"] != nil
36+
func (p PushMessage) IsDelete() bool {
37+
return p.ExtParams["delete"] == "1"
3938
}
4039

4140
const (
@@ -107,8 +106,7 @@ func ReCreateAPNS(maxClientCount int) error {
107106
func Push(msg *PushMessage) error {
108107
pl := payload.NewPayload().MutableContent()
109108
pushType := apns2.PushTypeAlert
110-
111-
if msg.IsEmptyAlert() {
109+
if msg.IsDelete() {
112110
// Silent push notification
113111
pl = pl.ContentAvailable()
114112
pushType = apns2.PushTypeBackground

route_push.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ func push(params map[string]interface{}) (int, error) {
251251
return 400, fmt.Errorf("device key is empty")
252252
}
253253

254-
if msg.IsEmptyAlert() && msg.IsEncrypted() {
254+
if msg.IsEmptyAlert() {
255255
// For encrypted push notifications, a Body is required; otherwise, APNs will discard the notification
256-
msg.Body = "Encrypted Message"
256+
msg.Body = "Empty Message"
257257
}
258258

259259
deviceToken, err := db.DeviceTokenByKey(msg.DeviceKey)

0 commit comments

Comments
 (0)