From 6c12751e270ccf5be4dccadefa33ef39d5a722cc Mon Sep 17 00:00:00 2001 From: BanTanger <88583317+BanTanger@users.noreply.github.com> Date: Fri, 14 Jul 2023 20:07:26 +0800 Subject: [PATCH 1/4] fix: implement of GetUsersOnlineStatus (#567) --- internal/api/user.go | 2 +- internal/msggateway/hub_server.go | 5 ----- pkg/common/db/cache/conversation.go | 6 +++--- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/internal/api/user.go b/internal/api/user.go index 28cb74509..baea8fed3 100644 --- a/internal/api/user.go +++ b/internal/api/user.go @@ -83,7 +83,7 @@ func (u *UserApi) GetUsersOnlineStatus(c *gin.Context) { msgClient := msggateway.NewMsgGatewayClient(v) reply, err := msgClient.GetUsersOnlineStatus(c, &req) if err != nil { - log.ZWarn(c, "GetUsersOnlineStatus rpc err", err) + log.ZWarn(c, "GetUsersOnlineStatus rpc err", err) continue } else { wsResult = append(wsResult, reply.SuccessResult...) diff --git a/internal/msggateway/hub_server.go b/internal/msggateway/hub_server.go index 81aade1cb..5b756bf92 100644 --- a/internal/msggateway/hub_server.go +++ b/internal/msggateway/hub_server.go @@ -25,9 +25,7 @@ import ( "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/prome" - "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" "github.com/OpenIMSDK/Open-IM-Server/pkg/startrpc" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils" @@ -84,9 +82,6 @@ func (s *Server) GetUsersOnlineStatus( ctx context.Context, req *msggateway.GetUsersOnlineStatusReq, ) (*msggateway.GetUsersOnlineStatusResp, error) { - if !tokenverify.IsAppManagerUid(ctx) { - return nil, errs.ErrNoPermission.Wrap("only app manager") - } var resp msggateway.GetUsersOnlineStatusResp for _, userID := range req.UserIDs { clients, ok := s.LongConnServer.GetUserAllCons(userID) diff --git a/pkg/common/db/cache/conversation.go b/pkg/common/db/cache/conversation.go index d3a9d44aa..119967c70 100644 --- a/pkg/common/db/cache/conversation.go +++ b/pkg/common/db/cache/conversation.go @@ -54,7 +54,7 @@ type ConversationCache interface { // get one conversation from msgCache GetConversation(ctx context.Context, ownerUserID, conversationID string) (*relationTb.ConversationModel, error) - DelConvsersations(ownerUserID string, conversationIDs ...string) ConversationCache + DelConversations(ownerUserID string, conversationIDs ...string) ConversationCache DelUsersConversation(conversationID string, ownerUserIDs ...string) ConversationCache // get one conversation from msgCache GetConversations( @@ -225,9 +225,9 @@ func (c *ConversationRedisCache) GetConversation( ) } -func (c *ConversationRedisCache) DelConvsersations(ownerUserID string, convsersationIDs ...string) ConversationCache { +func (c *ConversationRedisCache) DelConversations(ownerUserID string, conversationIDs ...string) ConversationCache { var keys []string - for _, conversationID := range convsersationIDs { + for _, conversationID := range conversationIDs { keys = append(keys, c.getConversationKey(ownerUserID, conversationID)) } cache := c.NewCache() From b5e5945b61b398fe1a4d676fd885bff50c4ac4cb Mon Sep 17 00:00:00 2001 From: BanTanger <88583317+BanTanger@users.noreply.github.com> Date: Mon, 17 Jul 2023 15:13:28 +0800 Subject: [PATCH 2/4] fix bug: obtain user online status err(#567) --- internal/api/user.go | 6 +++++- internal/msggateway/hub_server.go | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/api/user.go b/internal/api/user.go index baea8fed3..1e75b8fb4 100644 --- a/internal/api/user.go +++ b/internal/api/user.go @@ -84,7 +84,11 @@ func (u *UserApi) GetUsersOnlineStatus(c *gin.Context) { reply, err := msgClient.GetUsersOnlineStatus(c, &req) if err != nil { log.ZWarn(c, "GetUsersOnlineStatus rpc err", err) - continue + // apiresp.GinError(c, err) + parseError := apiresp.ParseError(err) + if parseError.ErrCode == errs.NoPermissionError { + apiresp.GinError(c, err) + } } else { wsResult = append(wsResult, reply.SuccessResult...) } diff --git a/internal/msggateway/hub_server.go b/internal/msggateway/hub_server.go index 6d852515c..992943fe9 100644 --- a/internal/msggateway/hub_server.go +++ b/internal/msggateway/hub_server.go @@ -16,6 +16,8 @@ package msggateway import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify" + "github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" From 459efacd3c36eef3b1a78d3f26458ad2d5992c72 Mon Sep 17 00:00:00 2001 From: BanTanger <88583317+BanTanger@users.noreply.github.com> Date: Mon, 17 Jul 2023 16:29:01 +0800 Subject: [PATCH 3/4] fix bug: obtain user online status err(#567) --- internal/msggateway/hub_server.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/msggateway/hub_server.go b/internal/msggateway/hub_server.go index 992943fe9..deb8c3d77 100644 --- a/internal/msggateway/hub_server.go +++ b/internal/msggateway/hub_server.go @@ -16,11 +16,10 @@ package msggateway import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" - "google.golang.org/grpc" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" @@ -84,6 +83,9 @@ func (s *Server) GetUsersOnlineStatus( ctx context.Context, req *msggateway.GetUsersOnlineStatusReq, ) (*msggateway.GetUsersOnlineStatusResp, error) { + if !tokenverify.IsAppManagerUid(ctx) { + return nil, errs.ErrNoPermission.Wrap("only app manager") + } var resp msggateway.GetUsersOnlineStatusResp for _, userID := range req.UserIDs { clients, ok := s.LongConnServer.GetUserAllCons(userID) From a06de3c7d7d7fac799243e9a1b7f2c9e1849c799 Mon Sep 17 00:00:00 2001 From: BanTanger <88583317+BanTanger@users.noreply.github.com> Date: Mon, 17 Jul 2023 16:30:48 +0800 Subject: [PATCH 4/4] fix bug: obtain user online status err(#567) --- internal/msggateway/hub_server.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/msggateway/hub_server.go b/internal/msggateway/hub_server.go index 992943fe9..deb8c3d77 100644 --- a/internal/msggateway/hub_server.go +++ b/internal/msggateway/hub_server.go @@ -16,11 +16,10 @@ package msggateway import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" - "google.golang.org/grpc" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" @@ -84,6 +83,9 @@ func (s *Server) GetUsersOnlineStatus( ctx context.Context, req *msggateway.GetUsersOnlineStatusReq, ) (*msggateway.GetUsersOnlineStatusResp, error) { + if !tokenverify.IsAppManagerUid(ctx) { + return nil, errs.ErrNoPermission.Wrap("only app manager") + } var resp msggateway.GetUsersOnlineStatusResp for _, userID := range req.UserIDs { clients, ok := s.LongConnServer.GetUserAllCons(userID)