diff --git a/internal/rpc/msg/as_read.go b/internal/rpc/msg/as_read.go index b65554a6d..016937040 100644 --- a/internal/rpc/msg/as_read.go +++ b/internal/rpc/msg/as_read.go @@ -21,6 +21,16 @@ func (m *msgServer) GetConversationsHasReadAndMaxSeq(ctx context.Context, req *m if err != nil { return nil, err } + conversations, err := m.Conversation.GetConversations(ctx, req.UserID, conversationIDs) + if err != nil { + return nil, err + } + var conversationMaxSeqMap = make(map[string]int64) + for _, conversation := range conversations { + if conversation.MaxSeq != 0 { + conversationMaxSeqMap[conversation.ConversationID] = conversation.MaxSeq + } + } maxSeqs, err := m.MsgDatabase.GetMaxSeqs(ctx, conversationIDs) if err != nil { return nil, err @@ -31,6 +41,9 @@ func (m *msgServer) GetConversationsHasReadAndMaxSeq(ctx context.Context, req *m HasReadSeq: hasReadSeqs[conversarionID], MaxSeq: maxSeq, } + if v, ok := conversationMaxSeqMap[conversarionID]; ok { + resp.Seqs[conversarionID].MaxSeq = v + } } return resp, nil } diff --git a/pkg/rpcclient/conversation.go b/pkg/rpcclient/conversation.go index cbf972b7f..c0522f492 100644 --- a/pkg/rpcclient/conversation.go +++ b/pkg/rpcclient/conversation.go @@ -107,3 +107,15 @@ func (c *ConversationClient) GetConversationsByConversationID(ctx context.Contex } return resp.Conversations, nil } + +func (c *ConversationClient) GetConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*pbConversation.Conversation, error) { + cc, err := c.getConn(ctx) + if err != nil { + return nil, err + } + resp, err := pbConversation.NewConversationClient(cc).GetConversations(ctx, &pbConversation.GetConversationsReq{OwnerUserID: ownerUserID, ConversationIDs: conversationIDs}) + if err != nil { + return nil, err + } + return resp.Conversations, nil +}