From 5d617cc2405bb5da4fbf20c1ef9bdd0b57e41e99 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 4 May 2023 16:06:17 +0800 Subject: [PATCH] conversation --- internal/rpc/msg/server.go | 54 +++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/internal/rpc/msg/server.go b/internal/rpc/msg/server.go index 4a986f163..60a1bb6ef 100644 --- a/internal/rpc/msg/server.go +++ b/internal/rpc/msg/server.go @@ -22,17 +22,18 @@ import ( type MessageInterceptorChain []MessageInterceptorFunc type msgServer struct { - RegisterCenter discoveryregistry.SvcDiscoveryRegistry - MsgDatabase controller.MsgDatabase - ExtendMsgDatabase controller.ExtendMsgDatabase - Group *rpcclient.GroupClient - User *rpcclient.UserClient - Conversation *rpcclient.ConversationClient - friend *rpcclient.FriendClient - black *rpcclient.BlackClient - GroupLocalCache *localcache.GroupLocalCache - MessageLocker MessageLocker - Handlers MessageInterceptorChain + RegisterCenter discoveryregistry.SvcDiscoveryRegistry + MsgDatabase controller.MsgDatabase + notificationDatabase controller.NotificationDatabase + ExtendMsgDatabase controller.ExtendMsgDatabase + Group *rpcclient.GroupClient + User *rpcclient.UserClient + Conversation *rpcclient.ConversationClient + friend *rpcclient.FriendClient + black *rpcclient.BlackClient + GroupLocalCache *localcache.GroupLocalCache + MessageLocker MessageLocker + Handlers MessageInterceptorChain } func (m *msgServer) addInterceptorHandler(interceptorFunc ...MessageInterceptorFunc) { @@ -161,14 +162,31 @@ func (m *msgServer) GetMaxAndMinSeq(ctx context.Context, req *sdkws.GetMaxAndMin func (m *msgServer) PullMessageBySeqs(ctx context.Context, req *sdkws.PullMessageBySeqsReq) (*sdkws.PullMessageBySeqsResp, error) { resp := &sdkws.PullMessageBySeqsResp{} for _, seq := range req.SeqRanges { - msgs, err := m.MsgDatabase.GetMsgBySeqsRange(ctx, seq.ConversationID, seq.Begin, seq.End, seq.Num) - if err != nil { - return nil, err + if !seq.IsNotification { + msgs, err := m.MsgDatabase.GetMsgBySeqsRange(ctx, seq.ConversationID, seq.Begin, seq.End, seq.Num) + if err != nil { + return nil, err + } + resp.Msgs = append(resp.Msgs, &sdkws.PullMsgs{ + ConversationID: seq.ConversationID, + Msgs: msgs, + }) + } else { + var seqs []int64 + for i := seq.Begin; i <= seq.End; i++ { + seqs = append(seqs, i) + } + msgs, err := m.notificationDatabase.GetMsgBySeqs(ctx, seq.ConversationID, seqs) + if err != nil { + return nil, err + } + resp.Msgs = append(resp.Msgs, &sdkws.PullMsgs{ + ConversationID: seq.ConversationID, + Msgs: msgs, + IsNotification: true, + }) } - resp.Msgs = append(resp.Msgs, &sdkws.PullMsgs{ - ConversationID: seq.ConversationID, - Msgs: msgs, - }) + } return resp, nil }