Skip to content

Commit 41a26c1

Browse files
authored
Merge pull request #3174 from icey-yu/fix-push
fix: Offline push does not have a badge && Android offline push (#3146)
2 parents cb4ac19 + 5e0200c commit 41a26c1

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
lines changed

Diff for: internal/push/offlinepush/fcm/push.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ package fcm
1616

1717
import (
1818
"context"
19+
"errors"
1920
"fmt"
20-
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
21-
"github.com/openimsdk/tools/utils/httputil"
2221
"path/filepath"
2322
"strings"
2423

24+
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
25+
"github.com/openimsdk/tools/utils/httputil"
26+
2527
firebase "firebase.google.com/go/v4"
2628
"firebase.google.com/go/v4/messaging"
2729
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
@@ -133,7 +135,7 @@ func (f *Fcm) Push(ctx context.Context, userIDs []string, title, content string,
133135
unreadCountSum, err := f.cache.GetUserBadgeUnreadCountSum(ctx, userID)
134136
if err == nil && unreadCountSum != 0 {
135137
apns.Payload.Aps.Badge = &unreadCountSum
136-
} else if err == redis.Nil || unreadCountSum == 0 {
138+
} else if errors.Is(err, redis.Nil) || unreadCountSum == 0 {
137139
zero := 1
138140
apns.Payload.Aps.Badge = &zero
139141
} else {

Diff for: internal/push/offlinepush/getui/body.go

+36-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ import (
1818
"fmt"
1919

2020
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
21+
"github.com/openimsdk/tools/utils/datautil"
22+
)
23+
24+
var (
25+
incOne = datautil.ToPtr("+1")
26+
addNum = "1"
27+
defaultStrategy = strategy{
28+
Default: 1,
29+
}
30+
msgCategory = "CATEGORY_MESSAGE"
2131
)
2232

2333
type Resp struct {
@@ -58,7 +68,24 @@ type TaskResp struct {
5868
}
5969

6070
type Settings struct {
61-
TTL *int64 `json:"ttl"`
71+
TTL *int64 `json:"ttl"`
72+
Strategy strategy `json:"strategy"`
73+
}
74+
75+
type strategy struct {
76+
Default int64 `json:"default"`
77+
//IOS int64 `json:"ios"`
78+
//St int64 `json:"st"`
79+
//Hw int64 `json:"hw"`
80+
//Ho int64 `json:"ho"`
81+
//XM int64 `json:"xm"`
82+
//XMG int64 `json:"xmg"`
83+
//VV int64 `json:"vv"`
84+
//Op int64 `json:"op"`
85+
//OpG int64 `json:"opg"`
86+
//MZ int64 `json:"mz"`
87+
//HosHw int64 `json:"hoshw"`
88+
//WX int64 `json:"wx"`
6289
}
6390

6491
type Audience struct {
@@ -112,6 +139,8 @@ type Notification struct {
112139
ChannelID string `json:"channelID"`
113140
ChannelName string `json:"ChannelName"`
114141
ClickType string `json:"click_type"`
142+
BadgeAddNum string `json:"badge_add_num"`
143+
Category string `json:"category"`
115144
}
116145

117146
type Options struct {
@@ -120,6 +149,7 @@ type Options struct {
120149
ChannelID string `json:"/message/android/notification/channel_id"`
121150
Sound string `json:"/message/android/notification/sound"`
122151
Importance string `json:"/message/android/notification/importance"`
152+
Category string `json:"/message/android/category"`
123153
} `json:"HW"`
124154
XM struct {
125155
ChannelID string `json:"/extra.channel_id"`
@@ -140,6 +170,8 @@ func newPushReq(pushConf *config.Push, title, content string) PushReq {
140170
ClickType: "startapp",
141171
ChannelID: pushConf.GeTui.ChannelID,
142172
ChannelName: pushConf.GeTui.ChannelName,
173+
BadgeAddNum: addNum,
174+
Category: msgCategory,
143175
}}}
144176
return pushReq
145177
}
@@ -156,6 +188,7 @@ func (pushReq *PushReq) setPushChannel(title string, body string) {
156188
notify := "notify"
157189
pushReq.PushChannel.Ios.NotificationType = &notify
158190
pushReq.PushChannel.Ios.Aps.Sound = "default"
191+
pushReq.PushChannel.Ios.AutoBadge = incOne
159192
pushReq.PushChannel.Ios.Aps.Alert = Alert{
160193
Title: title,
161194
Body: body,
@@ -172,7 +205,8 @@ func (pushReq *PushReq) setPushChannel(title string, body string) {
172205
ChannelID string `json:"/message/android/notification/channel_id"`
173206
Sound string `json:"/message/android/notification/sound"`
174207
Importance string `json:"/message/android/notification/importance"`
175-
}{ChannelID: "RingRing4", Sound: "/raw/ring001", Importance: "NORMAL"},
208+
Category string `json:"/message/android/category"`
209+
}{ChannelID: "RingRing4", Sound: "/raw/ring001", Importance: "NORMAL", Category: "IM"},
176210
XM: struct {
177211
ChannelID string `json:"/extra.channel_id"`
178212
}{ChannelID: "high_system"},

Diff for: internal/push/offlinepush/getui/push.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"crypto/sha256"
2020
"encoding/hex"
21+
"errors"
2122
"strconv"
2223
"sync"
2324
"time"
@@ -70,7 +71,7 @@ func NewClient(pushConf *config.Push, cache cache.ThirdCache) *Client {
7071
func (g *Client) Push(ctx context.Context, userIDs []string, title, content string, opts *options.Opts) error {
7172
token, err := g.cache.GetGetuiToken(ctx)
7273
if err != nil {
73-
if errs.Unwrap(err) == redis.Nil {
74+
if errors.Is(err, redis.Nil) {
7475
log.ZDebug(ctx, "getui token not exist in redis")
7576
token, err = g.getTokenAndSave2Redis(ctx)
7677
if err != nil {
@@ -144,7 +145,7 @@ func (g *Client) Auth(ctx context.Context, timeStamp int64) (token string, expir
144145
func (g *Client) GetTaskID(ctx context.Context, token string, pushReq PushReq) (string, error) {
145146
respTask := TaskResp{}
146147
ttl := int64(1000 * 60 * 5)
147-
pushReq.Settings = &Settings{TTL: &ttl}
148+
pushReq.Settings = &Settings{TTL: &ttl, Strategy: defaultStrategy}
148149
err := g.request(ctx, taskURL, pushReq, token, &respTask)
149150
if err != nil {
150151
return "", errs.Wrap(err)
@@ -188,6 +189,7 @@ func (g *Client) postReturn(
188189
if err != nil {
189190
return err
190191
}
192+
log.ZDebug(ctx, "postReturn", "url", url, "header", header, "input", input, "timeout", timeout, "output", output)
191193
return output.parseError()
192194
}
193195

@@ -204,7 +206,7 @@ func (g *Client) getTokenAndSave2Redis(ctx context.Context) (token string, err e
204206
}
205207

206208
func (g *Client) GetTaskIDAndSave2Redis(ctx context.Context, token string, pushReq PushReq) (taskID string, err error) {
207-
pushReq.Settings = &Settings{TTL: &g.taskIDTTL}
209+
pushReq.Settings = &Settings{TTL: &g.taskIDTTL, Strategy: defaultStrategy}
208210
taskID, err = g.GetTaskID(ctx, token, pushReq)
209211
if err != nil {
210212
return

Diff for: pkg/common/storage/cache/redis/lua_script.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package redis
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
7+
68
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
79
"github.com/openimsdk/tools/errs"
810
"github.com/openimsdk/tools/log"
@@ -56,7 +58,7 @@ func callLua(ctx context.Context, rdb redis.Scripter, script *redis.Script, keys
5658
}
5759
}
5860
v, err := r.Result()
59-
if err == redis.Nil {
61+
if errors.Is(err, redis.Nil) {
6062
err = nil
6163
}
6264
return v, errs.WrapMsg(err, "call lua err", "scriptHash", script.Hash(), "keys", keys, "args", args)

0 commit comments

Comments
 (0)