mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
fix: offline push can display badge
This commit is contained in:
parent
ed416f8376
commit
1d72e1dce0
@ -16,12 +16,14 @@ package fcm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
|
|
||||||
"github.com/openimsdk/tools/utils/httputil"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
|
||||||
|
"github.com/openimsdk/tools/utils/httputil"
|
||||||
|
|
||||||
firebase "firebase.google.com/go/v4"
|
firebase "firebase.google.com/go/v4"
|
||||||
"firebase.google.com/go/v4/messaging"
|
"firebase.google.com/go/v4/messaging"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"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,
|
|||||||
unreadCountSum, err := f.cache.GetUserBadgeUnreadCountSum(ctx, userID)
|
unreadCountSum, err := f.cache.GetUserBadgeUnreadCountSum(ctx, userID)
|
||||||
if err == nil && unreadCountSum != 0 {
|
if err == nil && unreadCountSum != 0 {
|
||||||
apns.Payload.Aps.Badge = &unreadCountSum
|
apns.Payload.Aps.Badge = &unreadCountSum
|
||||||
} else if err == redis.Nil || unreadCountSum == 0 {
|
} else if errors.Is(err, redis.Nil) || unreadCountSum == 0 {
|
||||||
zero := 1
|
zero := 1
|
||||||
apns.Payload.Aps.Badge = &zero
|
apns.Payload.Aps.Badge = &zero
|
||||||
} else {
|
} else {
|
||||||
|
@ -18,6 +18,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
|
"github.com/openimsdk/tools/utils/datautil"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
incOne = datautil.ToPtr("+1")
|
||||||
|
addNum = "1"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Resp struct {
|
type Resp struct {
|
||||||
@ -112,6 +118,7 @@ type Notification struct {
|
|||||||
ChannelID string `json:"channelID"`
|
ChannelID string `json:"channelID"`
|
||||||
ChannelName string `json:"ChannelName"`
|
ChannelName string `json:"ChannelName"`
|
||||||
ClickType string `json:"click_type"`
|
ClickType string `json:"click_type"`
|
||||||
|
BadgeAddNum string `json:"badge_add_num"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
@ -140,6 +147,7 @@ func newPushReq(pushConf *config.Push, title, content string) PushReq {
|
|||||||
ClickType: "startapp",
|
ClickType: "startapp",
|
||||||
ChannelID: pushConf.GeTui.ChannelID,
|
ChannelID: pushConf.GeTui.ChannelID,
|
||||||
ChannelName: pushConf.GeTui.ChannelName,
|
ChannelName: pushConf.GeTui.ChannelName,
|
||||||
|
BadgeAddNum: addNum,
|
||||||
}}}
|
}}}
|
||||||
return pushReq
|
return pushReq
|
||||||
}
|
}
|
||||||
@ -156,6 +164,7 @@ func (pushReq *PushReq) setPushChannel(title string, body string) {
|
|||||||
notify := "notify"
|
notify := "notify"
|
||||||
pushReq.PushChannel.Ios.NotificationType = ¬ify
|
pushReq.PushChannel.Ios.NotificationType = ¬ify
|
||||||
pushReq.PushChannel.Ios.Aps.Sound = "default"
|
pushReq.PushChannel.Ios.Aps.Sound = "default"
|
||||||
|
pushReq.PushChannel.Ios.AutoBadge = incOne
|
||||||
pushReq.PushChannel.Ios.Aps.Alert = Alert{
|
pushReq.PushChannel.Ios.Aps.Alert = Alert{
|
||||||
Title: title,
|
Title: title,
|
||||||
Body: body,
|
Body: body,
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -70,7 +71,7 @@ func NewClient(pushConf *config.Push, cache cache.ThirdCache) *Client {
|
|||||||
func (g *Client) Push(ctx context.Context, userIDs []string, title, content string, opts *options.Opts) error {
|
func (g *Client) Push(ctx context.Context, userIDs []string, title, content string, opts *options.Opts) error {
|
||||||
token, err := g.cache.GetGetuiToken(ctx)
|
token, err := g.cache.GetGetuiToken(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errs.Unwrap(err) == redis.Nil {
|
if errors.Is(err, redis.Nil) {
|
||||||
log.ZDebug(ctx, "getui token not exist in redis")
|
log.ZDebug(ctx, "getui token not exist in redis")
|
||||||
token, err = g.getTokenAndSave2Redis(ctx)
|
token, err = g.getTokenAndSave2Redis(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
4
pkg/common/storage/cache/redis/lua_script.go
vendored
4
pkg/common/storage/cache/redis/lua_script.go
vendored
@ -2,7 +2,9 @@ package redis
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
||||||
"github.com/openimsdk/tools/errs"
|
"github.com/openimsdk/tools/errs"
|
||||||
"github.com/openimsdk/tools/log"
|
"github.com/openimsdk/tools/log"
|
||||||
@ -56,7 +58,7 @@ func callLua(ctx context.Context, rdb redis.Scripter, script *redis.Script, keys
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
v, err := r.Result()
|
v, err := r.Result()
|
||||||
if err == redis.Nil {
|
if errors.Is(err, redis.Nil) {
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
return v, errs.WrapMsg(err, "call lua err", "scriptHash", script.Hash(), "keys", keys, "args", args)
|
return v, errs.WrapMsg(err, "call lua err", "scriptHash", script.Hash(), "keys", keys, "args", args)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user