Merge remote-tracking branch 'origin/v2.3.0release' into v2.3.0release

This commit is contained in:
wenxu12345
2022-07-29 17:49:27 +08:00
6 changed files with 56 additions and 34 deletions
+12 -18
View File
@@ -5,10 +5,10 @@ import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/log"
"Open_IM/pkg/tools"
"context"
firebase "firebase.google.com/go"
"firebase.google.com/go/messaging"
"fmt"
"google.golang.org/api/option"
"path/filepath"
"strconv"
@@ -47,7 +47,6 @@ func newFcmClient() *Fcm {
}
func (f *Fcm) Push(accounts []string, alert, detailContent, operationID string, opts push.PushOpts) (string, error) {
//需要一个客户端的Token
// accounts->registrationToken
Tokens := make([]string, 0)
for _, account := range accounts {
@@ -61,23 +60,16 @@ func (f *Fcm) Push(accounts []string, alert, detailContent, operationID string,
Tokens = append(Tokens, AndroidfcmToken)
}
}
tokenlen := len(Tokens)
// 500组为一个推送,我们用400好了
pages := int((tokenlen-1)/SinglePushCountLimit + 1)
Success := 0
Fail := 0
fmt.Println(operationID, "fcm args", tokenlen, pages)
for i := 0; i < pages; i++ {
Msg := new(messaging.MulticastMessage)
Msg.Notification = &messaging.Notification{}
Msg.Notification.Body = detailContent
Msg.Notification.Title = alert
ctx := context.Background()
max := (i+1)*SinglePushCountLimit - 1
if max >= tokenlen {
max = tokenlen - 1
}
Msg.Tokens = Tokens[i*SinglePushCountLimit : max]
result := tools.NewSplitter(SinglePushCountLimit, Tokens).GetSplitResult()
Msg := new(messaging.MulticastMessage)
Msg.Notification = &messaging.Notification{}
Msg.Notification.Body = detailContent
Msg.Notification.Title = alert
ctx := context.Background()
for _, v := range result {
Msg.Tokens = v.Item
//SendMulticast sends the given multicast message to all the FCM registration tokens specified.
//The tokens array in MulticastMessage may contain up to 500 tokens.
//SendMulticast uses the `SendAll()` function to send the given message to all the target recipients.
@@ -87,7 +79,9 @@ func (f *Fcm) Push(accounts []string, alert, detailContent, operationID string,
//Partial failures are indicated by a `BatchResponse` return value.
response, err := f.FcmMsgCli.SendMulticast(ctx, Msg)
if err != nil {
return "", err
Fail = Fail + len(v.Item)
log.Info(operationID, "some token push err", err.Error(), len(v.Item))
continue
}
Success = Success + response.SuccessCount
Fail = Fail + response.FailureCount
+5 -1
View File
@@ -11,7 +11,7 @@ import (
http2 "net/http"
)
func callbackOfflinePush(operationID string, userIDList []string, msg *commonPb.MsgData) cbApi.CommonCallbackResp {
func callbackOfflinePush(operationID string, userIDList []string, msg *commonPb.MsgData, offlinePushUserIDList *[]string) cbApi.CommonCallbackResp {
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
if !config.Config.Callback.CallbackOfflinePush.Enable {
return callbackResp
@@ -46,6 +46,10 @@ func callbackOfflinePush(operationID string, userIDList []string, msg *commonPb.
return callbackResp
}
}
if resp.ErrCode == constant.CallbackHandleSuccess && resp.ActionCode == constant.ActionAllow && len(resp.UserIDList) != 0 {
*offlinePushUserIDList = resp.UserIDList
}
log.NewDebug(operationID, utils.GetSelfFuncName(), offlinePushUserIDList, resp.UserIDList)
return callbackResp
}
+10 -3
View File
@@ -127,7 +127,7 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
}
}
callbackResp := callbackOfflinePush(pushMsg.OperationID, UIDList, pushMsg.MsgData)
callbackResp := callbackOfflinePush(pushMsg.OperationID, UIDList, pushMsg.MsgData, &[]string{})
log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offline callback Resp")
if callbackResp.ErrCode != 0 {
log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "callbackOfflinePush result: ", callbackResp)
@@ -261,7 +261,9 @@ func MsgToSuperGroupUser(pushMsg *pbPush.PushMsgReq) {
}
}
if len(onlineFailedUserIDList) > 0 {
callbackResp := callbackOfflinePush(pushMsg.OperationID, onlineFailedUserIDList, pushMsg.MsgData)
var offlinePushUserIDList []string
var needOfflinePushUserIDList []string
callbackResp := callbackOfflinePush(pushMsg.OperationID, onlineFailedUserIDList, pushMsg.MsgData, &offlinePushUserIDList)
log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offline callback Resp")
if callbackResp.ErrCode != 0 {
log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "callbackOfflinePush result: ", callbackResp)
@@ -270,6 +272,11 @@ func MsgToSuperGroupUser(pushMsg *pbPush.PushMsgReq) {
log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offlinePush stop")
return
}
if len(offlinePushUserIDList) > 0 {
needOfflinePushUserIDList = offlinePushUserIDList
} else {
needOfflinePushUserIDList = onlineFailedUserIDList
}
if offlinePusher == nil {
return
}
@@ -278,7 +285,7 @@ func MsgToSuperGroupUser(pushMsg *pbPush.PushMsgReq) {
log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "GetOfflinePushOpts failed", pushMsg, err.Error())
}
log.NewInfo(pushMsg.OperationID, utils.GetSelfFuncName(), onlineFailedUserIDList, content, jsonCustomContent, "opts:", opts)
pushResult, err := offlinePusher.Push(onlineFailedUserIDList, content, jsonCustomContent, pushMsg.OperationID, opts)
pushResult, err := offlinePusher.Push(needOfflinePushUserIDList, content, jsonCustomContent, pushMsg.OperationID, opts)
if err != nil {
log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error())
} else {