Merge branch 'main' into localcache

# Conflicts:
#	go.mod
#	go.sum
#	internal/msggateway/hub_server.go
#	internal/push/consumer_init.go
#	internal/push/offlinepush/fcm/push.go
#	internal/push/offlinepush/getui/push.go
#	internal/push/offlinepush/jpush/push.go
#	internal/push/push_handler.go
#	internal/push/push_rpc_server.go
#	internal/push/push_to_client.go
#	internal/rpc/friend/friend.go
#	internal/rpc/msg/server.go
#	internal/rpc/msg/verify.go
#	pkg/common/config/config.go
#	pkg/common/db/cache/conversation.go
#	pkg/common/db/cache/meta_cache.go
#	pkg/common/db/cache/msg.go
#	pkg/common/db/localcache/conversation.go
#	pkg/common/db/localcache/group.go
#	pkg/rpcclient/conversation.go
#	pkg/rpcclient/group.go
This commit is contained in:
withchao
2024-03-07 11:59:53 +08:00
326 changed files with 7738 additions and 3878 deletions
+3 -3
View File
@@ -133,13 +133,13 @@ type Payload struct {
IsSignal bool `json:"isSignal"`
}
func newPushReq(title, content string) PushReq {
func newPushReq(config *config.GlobalConfig, title, content string) PushReq {
pushReq := PushReq{PushMessage: &PushMessage{Notification: &Notification{
Title: title,
Body: content,
ClickType: "startapp",
ChannelID: config.Config.Push.GeTui.ChannelID,
ChannelName: config.Config.Push.GeTui.ChannelName,
ChannelID: config.Push.GeTui.ChannelID,
ChannelName: config.Push.GeTui.ChannelName,
}}}
return pushReq
}
+26 -23
View File
@@ -24,18 +24,16 @@ import (
"sync"
"time"
"github.com/redis/go-redis/v9"
"github.com/OpenIMSDK/tools/errs"
"github.com/OpenIMSDK/tools/log"
"github.com/OpenIMSDK/tools/mcontext"
"github.com/OpenIMSDK/tools/utils/splitter"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
http2 "github.com/openimsdk/open-im-server/v3/pkg/common/http"
"github.com/OpenIMSDK/tools/utils"
"github.com/redis/go-redis/v9"
)
var (
@@ -59,13 +57,18 @@ type GeTui struct {
cache cache.MsgModel
tokenExpireTime int64
taskIDTTL int64
config *config.GlobalConfig
}
func NewGeTui(cache cache.MsgModel) *GeTui {
return &GeTui{cache: cache, tokenExpireTime: tokenExpireTime, taskIDTTL: taskIDTTL}
func NewClient(config *config.GlobalConfig, cache cache.MsgModel) *Client {
return &Client{cache: cache,
tokenExpireTime: tokenExpireTime,
taskIDTTL: taskIDTTL,
config: config,
}
}
func (g *GeTui) 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 *offlinepush.Opts) error {
token, err := g.cache.GetGetuiToken(ctx)
if err != nil {
if errs.Unwrap(err) == redis.Nil {
@@ -78,7 +81,7 @@ func (g *GeTui) Push(ctx context.Context, userIDs []string, title, content strin
return err
}
}
pushReq := newPushReq(title, content)
pushReq := newPushReq(g.config, title, content)
pushReq.setPushChannel(title, content)
if len(userIDs) > 1 {
maxNum := 999
@@ -89,9 +92,9 @@ func (g *GeTui) Push(ctx context.Context, userIDs []string, title, content strin
for i, v := range s.GetSplitResult() {
go func(index int, userIDs []string) {
defer wg.Done()
if err2 := g.batchPush(ctx, token, userIDs, pushReq); err2 != nil {
log.ZError(ctx, "batchPush failed", err2, "index", index, "token", token, "req", pushReq)
err = err2
if err := g.batchPush(ctx, token, userIDs, pushReq); err != nil {
log.ZError(ctx, "batchPush failed", err, "index", index, "token", token, "req", pushReq)
err = err
}
}(i, v.Item)
}
@@ -111,16 +114,16 @@ func (g *GeTui) Push(ctx context.Context, userIDs []string, title, content strin
return err
}
func (g *GeTui) Auth(ctx context.Context, timeStamp int64) (token string, expireTime int64, err error) {
func (g *Client) Auth(ctx context.Context, timeStamp int64) (token string, expireTime int64, err error) {
h := sha256.New()
h.Write(
[]byte(config.Config.Push.GeTui.AppKey + strconv.Itoa(int(timeStamp)) + config.Config.Push.GeTui.MasterSecret),
[]byte(g.config.Push.GeTui.AppKey + strconv.Itoa(int(timeStamp)) + g.config.Push.GeTui.MasterSecret),
)
sign := hex.EncodeToString(h.Sum(nil))
reqAuth := AuthReq{
Sign: sign,
Timestamp: strconv.Itoa(int(timeStamp)),
AppKey: config.Config.Push.GeTui.AppKey,
AppKey: g.config.Push.GeTui.AppKey,
}
respAuth := AuthResp{}
err = g.request(ctx, authURL, reqAuth, "", &respAuth)
@@ -131,19 +134,19 @@ func (g *GeTui) Auth(ctx context.Context, timeStamp int64) (token string, expire
return respAuth.Token, int64(expire), err
}
func (g *GeTui) GetTaskID(ctx context.Context, token string, pushReq PushReq) (string, error) {
func (g *Client) GetTaskID(ctx context.Context, token string, pushReq PushReq) (string, error) {
respTask := TaskResp{}
ttl := int64(1000 * 60 * 5)
pushReq.Settings = &Settings{TTL: &ttl}
err := g.request(ctx, taskURL, pushReq, token, &respTask)
if err != nil {
return "", utils.Wrap(err, "")
return "", errs.Wrap(err)
}
return respTask.TaskID, nil
}
// max num is 999.
func (g *GeTui) batchPush(ctx context.Context, token string, userIDs []string, pushReq PushReq) error {
func (g *Client) batchPush(ctx context.Context, token string, userIDs []string, pushReq PushReq) error {
taskID, err := g.GetTaskID(ctx, token, pushReq)
if err != nil {
return err
@@ -152,21 +155,21 @@ func (g *GeTui) batchPush(ctx context.Context, token string, userIDs []string, p
return g.request(ctx, batchPushURL, pushReq, token, nil)
}
func (g *GeTui) singlePush(ctx context.Context, token, userID string, pushReq PushReq) error {
func (g *Client) singlePush(ctx context.Context, token, userID string, pushReq PushReq) error {
operationID := mcontext.GetOperationID(ctx)
pushReq.RequestID = &operationID
pushReq.Audience = &Audience{Alias: []string{userID}}
return g.request(ctx, pushURL, pushReq, token, nil)
}
func (g *GeTui) request(ctx context.Context, url string, input any, token string, output any) error {
func (g *Client) request(ctx context.Context, url string, input any, token string, output any) error {
header := map[string]string{"token": token}
resp := &Resp{}
resp.Data = output
return g.postReturn(ctx, config.Config.Push.GeTui.PushUrl+url, header, input, resp, 3)
return g.postReturn(ctx, g.config.Push.GeTui.PushUrl+url, header, input, resp, 3)
}
func (g *GeTui) postReturn(
func (g *Client) postReturn(
ctx context.Context,
url string,
header map[string]string,
@@ -181,7 +184,7 @@ func (g *GeTui) postReturn(
return output.parseError()
}
func (g *GeTui) getTokenAndSave2Redis(ctx context.Context) (token string, err error) {
func (g *Client) getTokenAndSave2Redis(ctx context.Context) (token string, err error) {
token, _, err = g.Auth(ctx, time.Now().UnixNano()/1e6)
if err != nil {
return
@@ -193,7 +196,7 @@ func (g *GeTui) getTokenAndSave2Redis(ctx context.Context) (token string, err er
return token, nil
}
func (g *GeTui) GetTaskIDAndSave2Redis(ctx context.Context, token string, pushReq PushReq) (taskID string, err error) {
func (g *Client) GetTaskIDAndSave2Redis(ctx context.Context, token string, pushReq PushReq) (taskID string, err error) {
pushReq.Settings = &Settings{TTL: &g.taskIDTTL}
taskID, err = g.GetTaskID(ctx, token, pushReq)
if err != nil {