|
|
@ -17,22 +17,19 @@ package msggateway
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/OpenIMSDK/tools/mcontext"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/OpenIMSDK/tools/errs"
|
|
|
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/OpenIMSDK/protocol/constant"
|
|
|
|
"github.com/OpenIMSDK/protocol/constant"
|
|
|
|
"github.com/OpenIMSDK/protocol/msggateway"
|
|
|
|
"github.com/OpenIMSDK/protocol/msggateway"
|
|
|
|
"github.com/OpenIMSDK/tools/discoveryregistry"
|
|
|
|
"github.com/OpenIMSDK/tools/discoveryregistry"
|
|
|
|
|
|
|
|
"github.com/OpenIMSDK/tools/errs"
|
|
|
|
"github.com/OpenIMSDK/tools/log"
|
|
|
|
"github.com/OpenIMSDK/tools/log"
|
|
|
|
|
|
|
|
"github.com/OpenIMSDK/tools/mcontext"
|
|
|
|
"github.com/OpenIMSDK/tools/utils"
|
|
|
|
"github.com/OpenIMSDK/tools/utils"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
|
|
|
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/startrpc"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/startrpc"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -41,6 +38,7 @@ func (s *Server) InitServer(disCov discoveryregistry.SvcDiscoveryRegistry, serve
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
msgModel := cache.NewMsgCacheModel(rdb)
|
|
|
|
msgModel := cache.NewMsgCacheModel(rdb)
|
|
|
|
s.LongConnServer.SetDiscoveryRegistry(disCov)
|
|
|
|
s.LongConnServer.SetDiscoveryRegistry(disCov)
|
|
|
|
s.LongConnServer.SetCacheHandler(msgModel)
|
|
|
|
s.LongConnServer.SetCacheHandler(msgModel)
|
|
|
@ -97,22 +95,25 @@ func (s *Server) GetUsersOnlineStatus(
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
temp := new(msggateway.GetUsersOnlineStatusResp_SuccessResult)
|
|
|
|
|
|
|
|
temp.UserID = userID
|
|
|
|
uresp := new(msggateway.GetUsersOnlineStatusResp_SuccessResult)
|
|
|
|
|
|
|
|
uresp.UserID = userID
|
|
|
|
for _, client := range clients {
|
|
|
|
for _, client := range clients {
|
|
|
|
if client != nil {
|
|
|
|
if client == nil {
|
|
|
|
ps := new(msggateway.GetUsersOnlineStatusResp_SuccessDetail)
|
|
|
|
continue
|
|
|
|
ps.Platform = constant.PlatformIDToName(client.PlatformID)
|
|
|
|
|
|
|
|
ps.Status = constant.OnlineStatus
|
|
|
|
|
|
|
|
ps.ConnID = client.ctx.GetConnID()
|
|
|
|
|
|
|
|
ps.Token = client.token
|
|
|
|
|
|
|
|
ps.IsBackground = client.IsBackground
|
|
|
|
|
|
|
|
temp.Status = constant.OnlineStatus
|
|
|
|
|
|
|
|
temp.DetailPlatformStatus = append(temp.DetailPlatformStatus, ps)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ps := new(msggateway.GetUsersOnlineStatusResp_SuccessDetail)
|
|
|
|
|
|
|
|
ps.Platform = constant.PlatformIDToName(client.PlatformID)
|
|
|
|
|
|
|
|
ps.Status = constant.OnlineStatus
|
|
|
|
|
|
|
|
ps.ConnID = client.ctx.GetConnID()
|
|
|
|
|
|
|
|
ps.Token = client.token
|
|
|
|
|
|
|
|
ps.IsBackground = client.IsBackground
|
|
|
|
|
|
|
|
uresp.Status = constant.OnlineStatus
|
|
|
|
|
|
|
|
uresp.DetailPlatformStatus = append(uresp.DetailPlatformStatus, ps)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if temp.Status == constant.OnlineStatus {
|
|
|
|
if uresp.Status == constant.OnlineStatus {
|
|
|
|
resp.SuccessResult = append(resp.SuccessResult, temp)
|
|
|
|
resp.SuccessResult = append(resp.SuccessResult, uresp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &resp, nil
|
|
|
|
return &resp, nil
|
|
|
@ -129,50 +130,55 @@ func (s *Server) SuperGroupOnlineBatchPushOneMsg(
|
|
|
|
ctx context.Context,
|
|
|
|
ctx context.Context,
|
|
|
|
req *msggateway.OnlineBatchPushOneMsgReq,
|
|
|
|
req *msggateway.OnlineBatchPushOneMsgReq,
|
|
|
|
) (*msggateway.OnlineBatchPushOneMsgResp, error) {
|
|
|
|
) (*msggateway.OnlineBatchPushOneMsgResp, error) {
|
|
|
|
var singleUserResult []*msggateway.SingleMsgToUserResults
|
|
|
|
|
|
|
|
|
|
|
|
var singleUserResults []*msggateway.SingleMsgToUserResults
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range req.PushToUserIDs {
|
|
|
|
for _, v := range req.PushToUserIDs {
|
|
|
|
var resp []*msggateway.SingleMsgToUserPlatform
|
|
|
|
var resp []*msggateway.SingleMsgToUserPlatform
|
|
|
|
tempT := &msggateway.SingleMsgToUserResults{
|
|
|
|
results := &msggateway.SingleMsgToUserResults{
|
|
|
|
UserID: v,
|
|
|
|
UserID: v,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clients, ok := s.LongConnServer.GetUserAllCons(v)
|
|
|
|
clients, ok := s.LongConnServer.GetUserAllCons(v)
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
log.ZDebug(ctx, "push user not online", "userID", v)
|
|
|
|
log.ZDebug(ctx, "push user not online", "userID", v)
|
|
|
|
tempT.Resp = resp
|
|
|
|
results.Resp = resp
|
|
|
|
singleUserResult = append(singleUserResult, tempT)
|
|
|
|
singleUserResults = append(singleUserResults, results)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.ZDebug(ctx, "push user online", "clients", clients, "userID", v)
|
|
|
|
log.ZDebug(ctx, "push user online", "clients", clients, "userID", v)
|
|
|
|
for _, client := range clients {
|
|
|
|
for _, client := range clients {
|
|
|
|
if client != nil {
|
|
|
|
if client == nil {
|
|
|
|
temp := &msggateway.SingleMsgToUserPlatform{
|
|
|
|
continue
|
|
|
|
RecvID: v,
|
|
|
|
}
|
|
|
|
RecvPlatFormID: int32(client.PlatformID),
|
|
|
|
|
|
|
|
}
|
|
|
|
userPlatform := &msggateway.SingleMsgToUserPlatform{
|
|
|
|
if !client.IsBackground ||
|
|
|
|
RecvID: v,
|
|
|
|
(client.IsBackground == true && client.PlatformID != constant.IOSPlatformID) {
|
|
|
|
RecvPlatFormID: int32(client.PlatformID),
|
|
|
|
err := client.PushMessage(ctx, req.MsgData)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
if !client.IsBackground ||
|
|
|
|
temp.ResultCode = -2
|
|
|
|
(client.IsBackground && client.PlatformID != constant.IOSPlatformID) {
|
|
|
|
resp = append(resp, temp)
|
|
|
|
err := client.PushMessage(ctx, req.MsgData)
|
|
|
|
} else {
|
|
|
|
if err != nil {
|
|
|
|
if utils.IsContainInt(client.PlatformID, s.pushTerminal) {
|
|
|
|
userPlatform.ResultCode = -2
|
|
|
|
tempT.OnlinePush = true
|
|
|
|
resp = append(resp, userPlatform)
|
|
|
|
resp = append(resp, temp)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
temp.ResultCode = -3
|
|
|
|
if utils.IsContainInt(client.PlatformID, s.pushTerminal) {
|
|
|
|
resp = append(resp, temp)
|
|
|
|
results.OnlinePush = true
|
|
|
|
|
|
|
|
resp = append(resp, userPlatform)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
userPlatform.ResultCode = -3
|
|
|
|
|
|
|
|
resp = append(resp, userPlatform)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tempT.Resp = resp
|
|
|
|
results.Resp = resp
|
|
|
|
singleUserResult = append(singleUserResult, tempT)
|
|
|
|
singleUserResults = append(singleUserResults, results)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return &msggateway.OnlineBatchPushOneMsgResp{
|
|
|
|
return &msggateway.OnlineBatchPushOneMsgResp{
|
|
|
|
SinglePushResult: singleUserResult,
|
|
|
|
SinglePushResult: singleUserResults,
|
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -181,17 +187,21 @@ func (s *Server) KickUserOffline(
|
|
|
|
req *msggateway.KickUserOfflineReq,
|
|
|
|
req *msggateway.KickUserOfflineReq,
|
|
|
|
) (*msggateway.KickUserOfflineResp, error) {
|
|
|
|
) (*msggateway.KickUserOfflineResp, error) {
|
|
|
|
for _, v := range req.KickUserIDList {
|
|
|
|
for _, v := range req.KickUserIDList {
|
|
|
|
if clients, _, ok := s.LongConnServer.GetUserPlatformCons(v, int(req.PlatformID)); ok {
|
|
|
|
clients, _, ok := s.LongConnServer.GetUserPlatformCons(v, int(req.PlatformID))
|
|
|
|
for _, client := range clients {
|
|
|
|
if !ok {
|
|
|
|
log.ZDebug(ctx, "kick user offline", "userID", v, "platformID", req.PlatformID, "client", client)
|
|
|
|
|
|
|
|
if err := client.longConnServer.KickUserConn(client); err != nil {
|
|
|
|
|
|
|
|
log.ZWarn(ctx, "kick user offline failed", err, "userID", v, "platformID", req.PlatformID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.ZInfo(ctx, "conn not exist", "userID", v, "platformID", req.PlatformID)
|
|
|
|
log.ZInfo(ctx, "conn not exist", "userID", v, "platformID", req.PlatformID)
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, client := range clients {
|
|
|
|
|
|
|
|
log.ZDebug(ctx, "kick user offline", "userID", v, "platformID", req.PlatformID, "client", client)
|
|
|
|
|
|
|
|
if err := client.longConnServer.KickUserConn(client); err != nil {
|
|
|
|
|
|
|
|
log.ZWarn(ctx, "kick user offline failed", err, "userID", v, "platformID", req.PlatformID)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return &msggateway.KickUserOfflineResp{}, nil
|
|
|
|
return &msggateway.KickUserOfflineResp{}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|