diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7f4..35eb1ddfb 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/internal/api/user.go b/internal/api/user.go index 2f7352c41..e39b1488c 100644 --- a/internal/api/user.go +++ b/internal/api/user.go @@ -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) {