mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-09 03:25:59 +08:00
feat: provide the interface required by js sdk (#2664)
* fix: redis support acquisition time * fix: GetActiveConversation * feat: jssdk GetConversations, GetActiveConversation * feat: jssdk GetConversations, GetActiveConversation * feat: jssdk GetConversations, GetActiveConversation * feat: jssdk GetConversations, GetActiveConversation * feat: jssdk GetConversations, GetActiveConversation
This commit is contained in:
+24
-2
@@ -16,10 +16,10 @@ package msg
|
||||
|
||||
import (
|
||||
"context"
|
||||
pbmsg "github.com/openimsdk/protocol/msg"
|
||||
"github.com/openimsdk/tools/errs"
|
||||
"github.com/redis/go-redis/v9"
|
||||
|
||||
pbmsg "github.com/openimsdk/protocol/msg"
|
||||
"sort"
|
||||
)
|
||||
|
||||
func (m *msgServer) GetConversationMaxSeq(ctx context.Context, req *pbmsg.GetConversationMaxSeqReq) (*pbmsg.GetConversationMaxSeqResp, error) {
|
||||
@@ -62,3 +62,25 @@ func (m *msgServer) SetUserConversationsMinSeq(ctx context.Context, req *pbmsg.S
|
||||
}
|
||||
return &pbmsg.SetUserConversationsMinSeqResp{}, nil
|
||||
}
|
||||
|
||||
func (m *msgServer) GetActiveConversation(ctx context.Context, req *pbmsg.GetActiveConversationReq) (*pbmsg.GetActiveConversationResp, error) {
|
||||
res, err := m.MsgDatabase.GetCacheMaxSeqWithTime(ctx, req.ConversationIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
conversations := make([]*pbmsg.ActiveConversation, 0, len(res))
|
||||
for conversationID, val := range res {
|
||||
conversations = append(conversations, &pbmsg.ActiveConversation{
|
||||
MaxSeq: val.Seq,
|
||||
LastTime: val.Time,
|
||||
ConversationID: conversationID,
|
||||
})
|
||||
}
|
||||
if req.Limit > 0 {
|
||||
sort.Sort(activeConversations(conversations))
|
||||
if len(conversations) > int(req.Limit) {
|
||||
conversations = conversations[:req.Limit]
|
||||
}
|
||||
}
|
||||
return &pbmsg.GetActiveConversationResp{Conversations: conversations}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user