mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
parent
fea3c5358a
commit
ec6036b5fa
2
.idea/vcs.xml
generated
2
.idea/vcs.xml
generated
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -3,11 +3,9 @@ package api
|
||||
import (
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/apiresp"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/apistruct"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msggateway"
|
||||
@ -51,15 +49,54 @@ func (u *UserApi) GetUsers(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (u *UserApi) GetUsersOnlineStatus(c *gin.Context) {
|
||||
params := apistruct.ManagementSendMsgReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
var req msggateway.GetUsersOnlineStatusReq
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap())
|
||||
return
|
||||
}
|
||||
if !tokenverify.IsAppManagerUid(c) {
|
||||
apiresp.GinError(c, errs.ErrNoPermission.Wrap("only app manager can send message"))
|
||||
conns, err := u.Discov.GetConns(c, config.Config.RpcRegisterName.OpenImMessageGatewayName)
|
||||
if err != nil {
|
||||
apiresp.GinError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
var wsResult []*msggateway.GetUsersOnlineStatusResp_SuccessResult
|
||||
var respResult []*msggateway.GetUsersOnlineStatusResp_SuccessResult
|
||||
flag := false
|
||||
|
||||
//Online push message
|
||||
for _, v := range conns {
|
||||
msgClient := msggateway.NewMsgGatewayClient(v)
|
||||
reply, err := msgClient.GetUsersOnlineStatus(c, &req)
|
||||
if err != nil {
|
||||
log.ZWarn(c, "GetUsersOnlineStatus rpc err", err)
|
||||
continue
|
||||
} else {
|
||||
wsResult = append(wsResult, reply.SuccessResult...)
|
||||
}
|
||||
}
|
||||
// 遍历 api 请求体中的 userIDs
|
||||
for _, v1 := range req.UserIDs {
|
||||
flag = false
|
||||
res := new(msggateway.GetUsersOnlineStatusResp_SuccessResult)
|
||||
// 遍历从各个网关中获取的在线结果
|
||||
for _, v2 := range wsResult {
|
||||
// 如果匹配上说明在线,反之
|
||||
if v2.UserID == v1 {
|
||||
flag = true
|
||||
res.UserID = v1
|
||||
res.Status = constant.OnlineStatus
|
||||
res.DetailPlatformStatus = append(res.DetailPlatformStatus, v2.DetailPlatformStatus...)
|
||||
break
|
||||
}
|
||||
}
|
||||
if !flag {
|
||||
res.UserID = v1
|
||||
res.Status = constant.OnlineStatus
|
||||
}
|
||||
respResult = append(respResult, res)
|
||||
}
|
||||
apiresp.GinSuccess(c, respResult)
|
||||
}
|
||||
|
||||
func (u *UserApi) UserRegisterCount(c *gin.Context) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user