mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-25 02:58:26 +08:00
Merge branch 'v2.3.0release' of github.com:OpenIMSDK/Open-IM-Server into v2.3.0release
This commit is contained in:
commit
b29f93dcd2
@ -54,7 +54,7 @@ func (ws *WServer) msgParse(conn *UserConn, binaryMsg []byte) {
|
|||||||
ws.pullMsgBySeqListReq(conn, &m)
|
ws.pullMsgBySeqListReq(conn, &m)
|
||||||
case constant.WsLogoutMsg:
|
case constant.WsLogoutMsg:
|
||||||
log.NewInfo(m.OperationID, "conn.Close()", m.SendID, m.MsgIncr, m.ReqIdentifier)
|
log.NewInfo(m.OperationID, "conn.Close()", m.SendID, m.MsgIncr, m.ReqIdentifier)
|
||||||
conn.Close()
|
// conn.Close()
|
||||||
default:
|
default:
|
||||||
log.Error(m.OperationID, "ReqIdentifier failed ", m.SendID, m.MsgIncr, m.ReqIdentifier)
|
log.Error(m.OperationID, "ReqIdentifier failed ", m.SendID, m.MsgIncr, m.ReqIdentifier)
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ func (ws *WServer) addUserConn(uid string, platformID int, conn *UserConn, token
|
|||||||
if callbackResp.ErrCode != 0 {
|
if callbackResp.ErrCode != 0 {
|
||||||
log.NewError(operationID, utils.GetSelfFuncName(), "callbackUserOnline resp:", callbackResp)
|
log.NewError(operationID, utils.GetSelfFuncName(), "callbackUserOnline resp:", callbackResp)
|
||||||
}
|
}
|
||||||
go ws.MultiTerminalLoginRemoteChecker(uid, int32(platformID), token, operationID)
|
//go ws.MultiTerminalLoginRemoteChecker(uid, int32(platformID), token, operationID)
|
||||||
ws.MultiTerminalLoginChecker(uid, platformID, conn, token, operationID)
|
ws.MultiTerminalLoginChecker(uid, platformID, conn, token, operationID)
|
||||||
if oldConnMap, ok := ws.wsUserToConn[uid]; ok {
|
if oldConnMap, ok := ws.wsUserToConn[uid]; ok {
|
||||||
oldConnMap[platformID] = conn
|
oldConnMap[platformID] = conn
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/db"
|
"Open_IM/pkg/common/db"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
|
"Open_IM/pkg/tools"
|
||||||
"context"
|
"context"
|
||||||
firebase "firebase.google.com/go"
|
firebase "firebase.google.com/go"
|
||||||
"firebase.google.com/go/messaging"
|
"firebase.google.com/go/messaging"
|
||||||
@ -13,6 +14,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const SinglePushCountLimit = 400
|
||||||
|
|
||||||
type Fcm struct {
|
type Fcm struct {
|
||||||
FcmMsgCli *messaging.Client
|
FcmMsgCli *messaging.Client
|
||||||
}
|
}
|
||||||
@ -44,7 +47,6 @@ func newFcmClient() *Fcm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Fcm) Push(accounts []string, alert, detailContent, operationID string, opts push.PushOpts) (string, error) {
|
func (f *Fcm) Push(accounts []string, alert, detailContent, operationID string, opts push.PushOpts) (string, error) {
|
||||||
//需要一个客户端的Token
|
|
||||||
// accounts->registrationToken
|
// accounts->registrationToken
|
||||||
Tokens := make([]string, 0)
|
Tokens := make([]string, 0)
|
||||||
for _, account := range accounts {
|
for _, account := range accounts {
|
||||||
@ -58,22 +60,16 @@ func (f *Fcm) Push(accounts []string, alert, detailContent, operationID string,
|
|||||||
Tokens = append(Tokens, AndroidfcmToken)
|
Tokens = append(Tokens, AndroidfcmToken)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tokenlen := len(Tokens)
|
|
||||||
// 500组为一个推送,我们用400好了
|
|
||||||
limit := 400
|
|
||||||
pages := int((tokenlen-1)/limit + 1)
|
|
||||||
Success := 0
|
Success := 0
|
||||||
Fail := 0
|
Fail := 0
|
||||||
for i := 0; i < pages; i++ {
|
result := tools.NewSplitter(SinglePushCountLimit, Tokens).GetSplitResult()
|
||||||
Msg := new(messaging.MulticastMessage)
|
Msg := new(messaging.MulticastMessage)
|
||||||
|
Msg.Notification = &messaging.Notification{}
|
||||||
Msg.Notification.Body = detailContent
|
Msg.Notification.Body = detailContent
|
||||||
Msg.Notification.Title = alert
|
Msg.Notification.Title = alert
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
max := (i+1)*limit - 1
|
for _, v := range result {
|
||||||
if max >= tokenlen {
|
Msg.Tokens = v.Item
|
||||||
max = tokenlen - 1
|
|
||||||
}
|
|
||||||
Msg.Tokens = Tokens[i*limit : max]
|
|
||||||
//SendMulticast sends the given multicast message to all the FCM registration tokens specified.
|
//SendMulticast sends the given multicast message to all the FCM registration tokens specified.
|
||||||
//The tokens array in MulticastMessage may contain up to 500 tokens.
|
//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.
|
//SendMulticast uses the `SendAll()` function to send the given message to all the target recipients.
|
||||||
@ -83,7 +79,9 @@ func (f *Fcm) Push(accounts []string, alert, detailContent, operationID string,
|
|||||||
//Partial failures are indicated by a `BatchResponse` return value.
|
//Partial failures are indicated by a `BatchResponse` return value.
|
||||||
response, err := f.FcmMsgCli.SendMulticast(ctx, Msg)
|
response, err := f.FcmMsgCli.SendMulticast(ctx, Msg)
|
||||||
if err != nil {
|
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
|
Success = Success + response.SuccessCount
|
||||||
Fail = Fail + response.FailureCount
|
Fail = Fail + response.FailureCount
|
||||||
|
28
pkg/tools/tools.go
Normal file
28
pkg/tools/tools.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package tools
|
||||||
|
|
||||||
|
type SplitResult struct {
|
||||||
|
Item []string
|
||||||
|
}
|
||||||
|
type Splitter struct {
|
||||||
|
splitCount int
|
||||||
|
data []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSplitter(splitCount int, data []string) *Splitter {
|
||||||
|
return &Splitter{splitCount: splitCount, data: data}
|
||||||
|
}
|
||||||
|
func (s *Splitter) GetSplitResult() (result []*SplitResult) {
|
||||||
|
remain := len(s.data) % s.splitCount
|
||||||
|
integer := len(s.data) / s.splitCount
|
||||||
|
for i := 0; i < integer; i++ {
|
||||||
|
r := new(SplitResult)
|
||||||
|
r.Item = s.data[i*s.splitCount : (i+1)*s.splitCount]
|
||||||
|
result = append(result, r)
|
||||||
|
}
|
||||||
|
if remain > 0 {
|
||||||
|
r := new(SplitResult)
|
||||||
|
r.Item = s.data[integer*s.splitCount:]
|
||||||
|
result = append(result, r)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user