From 89b59eb82eacf7eecbc6aca37a4cbfafdd4335a8 Mon Sep 17 00:00:00 2001 From: luhaoling <2198702716@qq.com> Date: Tue, 9 Jan 2024 18:48:58 +0800 Subject: [PATCH 1/2] fix: fix the valiable name --- go.mod | 2 +- internal/api/conversation.go | 4 ++-- internal/api/route.go | 2 +- internal/rpc/conversation/conversaion.go | 18 +++++++++--------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 345cf044d..5e8e7275b 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( firebase.google.com/go v3.13.0+incompatible - github.com/OpenIMSDK/protocol v0.0.46 + github.com/OpenIMSDK/protocol v0.0.47 github.com/OpenIMSDK/tools v0.0.23 github.com/bwmarrin/snowflake v0.3.0 // indirect github.com/dtm-labs/rockscache v0.1.1 diff --git a/internal/api/conversation.go b/internal/api/conversation.go index 6463cbde6..eb735e550 100644 --- a/internal/api/conversation.go +++ b/internal/api/conversation.go @@ -33,8 +33,8 @@ func (o *ConversationApi) GetAllConversations(c *gin.Context) { a2r.Call(conversation.ConversationClient.GetAllConversations, o.Client, c) } -func (o *ConversationApi) GetConversationsList(c *gin.Context) { - a2r.Call(conversation.ConversationClient.GetConversationList, o.Client, c) +func (o *ConversationApi) GetSortedConversationList(c *gin.Context) { + a2r.Call(conversation.ConversationClient.GetSortedConversationList, o.Client, c) } func (o *ConversationApi) GetConversation(c *gin.Context) { diff --git a/internal/api/route.go b/internal/api/route.go index 1c91f4dde..fa34f109a 100644 --- a/internal/api/route.go +++ b/internal/api/route.go @@ -204,7 +204,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive conversationGroup := r.Group("/conversation", ParseToken) { c := NewConversationApi(*conversationRpc) - conversationGroup.POST("/get_conversations_list", c.GetConversationsList) + conversationGroup.POST("/get_sorted_conversation_list", c.GetSortedConversationList) conversationGroup.POST("/get_all_conversations", c.GetAllConversations) conversationGroup.POST("/get_conversation", c.GetConversation) conversationGroup.POST("/get_conversations", c.GetConversations) diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go index b80e32953..9ce5a3b67 100644 --- a/internal/rpc/conversation/conversaion.go +++ b/internal/rpc/conversation/conversaion.go @@ -89,7 +89,7 @@ func (c *conversationServer) GetConversation(ctx context.Context, req *pbconvers return resp, nil } -func (m *conversationServer) GetConversationList(ctx context.Context, req *pbconversation.GetConversationListReq) (resp *pbconversation.GetConversationListResp, err error) { +func (m *conversationServer) GetSortedConversationList(ctx context.Context, req *pbconversation.GetSortedConversationListReq) (resp *pbconversation.GetSortedConversationListResp, err error) { log.ZDebug(ctx, "GetConversationList", "seqs", req, "userID", req.UserID) var conversationIDs []string if len(req.ConversationIDs) == 0 { @@ -134,25 +134,25 @@ func (m *conversationServer) GetConversationList(ctx context.Context, req *pbcon conversation_unreadCount[conversationID] = maxSeq - hasReadSeqs[conversationID] } - conversation_isPinkTime := make(map[int64]string) - conversation_notPinkTime := make(map[int64]string) + conversation_isPinTime := make(map[int64]string) + conversation_notPinTime := make(map[int64]string) for _, v := range conversations { conversationID := v.ConversationID time := conversationMsg[conversationID].MsgInfo.LatestMsgRecvTime conversationMsg[conversationID].RecvMsgOpt = v.RecvMsgOpt if v.IsPinned { conversationMsg[conversationID].IsPinned = v.IsPinned - conversation_isPinkTime[time] = conversationID + conversation_isPinTime[time] = conversationID continue } - conversation_notPinkTime[time] = conversationID + conversation_notPinTime[time] = conversationID } - resp = &pbconversation.GetConversationListResp{ + resp = &pbconversation.GetSortedConversationListResp{ ConversationElems: []*pbconversation.ConversationElem{}, } - m.conversationSort(conversation_isPinkTime, resp, conversation_unreadCount, conversationMsg) - m.conversationSort(conversation_notPinkTime, resp, conversation_unreadCount, conversationMsg) + m.conversationSort(conversation_isPinTime, resp, conversation_unreadCount, conversationMsg) + m.conversationSort(conversation_notPinTime, resp, conversation_unreadCount, conversationMsg) return resp, nil } @@ -425,7 +425,7 @@ func (c *conversationServer) GetConversationOfflinePushUserIDs( func (c *conversationServer) conversationSort( conversations map[int64]string, - resp *pbconversation.GetConversationListResp, + resp *pbconversation.GetSortedConversationListResp, conversation_unreadCount map[string]int64, conversationMsg map[string]*pbconversation.ConversationElem, ) { From 159822e207508a280445486585f8081fb15412e2 Mon Sep 17 00:00:00 2001 From: luhaoling <2198702716@qq.com> Date: Tue, 9 Jan 2024 18:58:17 +0800 Subject: [PATCH 2/2] fix: fix the getSortedConversation api --- internal/rpc/conversation/conversaion.go | 11 +++++++++-- internal/rpc/user/user.go | 5 +++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go index 9ce5a3b67..d0d59547c 100644 --- a/internal/rpc/conversation/conversaion.go +++ b/internal/rpc/conversation/conversaion.go @@ -90,7 +90,7 @@ func (c *conversationServer) GetConversation(ctx context.Context, req *pbconvers } func (m *conversationServer) GetSortedConversationList(ctx context.Context, req *pbconversation.GetSortedConversationListReq) (resp *pbconversation.GetSortedConversationListResp, err error) { - log.ZDebug(ctx, "GetConversationList", "seqs", req, "userID", req.UserID) + log.ZDebug(ctx, "GetSortedConversationList", "seqs", req, "userID", req.UserID) var conversationIDs []string if len(req.ConversationIDs) == 0 { conversationIDs, err = m.conversationDatabase.GetConversationIDs(ctx, req.UserID) @@ -129,9 +129,12 @@ func (m *conversationServer) GetSortedConversationList(ctx context.Context, req return nil, err } + var unreadTotal int64 conversation_unreadCount := make(map[string]int64) for conversationID, maxSeq := range maxSeqs { - conversation_unreadCount[conversationID] = maxSeq - hasReadSeqs[conversationID] + unreadCount := maxSeq - hasReadSeqs[conversationID] + conversation_unreadCount[conversationID] = unreadCount + unreadTotal += unreadCount } conversation_isPinTime := make(map[int64]string) @@ -148,11 +151,15 @@ func (m *conversationServer) GetSortedConversationList(ctx context.Context, req conversation_notPinTime[time] = conversationID } resp = &pbconversation.GetSortedConversationListResp{ + ConversationTotal: int64(len(chatLogs)), ConversationElems: []*pbconversation.ConversationElem{}, + UnreadTotal: unreadTotal, } m.conversationSort(conversation_isPinTime, resp, conversation_unreadCount, conversationMsg) m.conversationSort(conversation_notPinTime, resp, conversation_unreadCount, conversationMsg) + + resp.ConversationElems = utils.Paginate(resp.ConversationElems, int(req.Pagination.GetPageNumber()), int(req.Pagination.GetShowNumber())) return resp, nil } diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 74d4a7512..5680c2b3d 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -429,6 +429,11 @@ func (s *userServer) AddNotificationAccount(ctx context.Context, req *pbuser.Add if req.UserID == "" { return nil, errs.ErrInternalServer.Wrap("gen user id failed") } + } else { + _, err := s.UserDatabase.FindWithError(ctx, []string{req.UserID}) + if err == nil { + return nil, errs.ErrArgs.Wrap("userID is used") + } } user := &tablerelation.UserModel{