fix: fix the error

pull/1672/head
luhaoling 2 years ago
parent afcea3212c
commit 1cf4ea5332

@ -155,4 +155,4 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect
) )
replace github.com/OpenIMSDK/protocol => github.com/luhaoling/protocol v0.0.0-20231223094538-101234d675fc replace github.com/OpenIMSDK/protocol => github.com/luhaoling/protocol v0.0.0-20231223120310-24a70ff4b1c7

@ -225,8 +225,8 @@ github.com/lestrrat-go/strftime v1.0.6 h1:CFGsDEt1pOpFNU+TJB0nhz9jl+K0hZSLE205Ah
github.com/lestrrat-go/strftime v1.0.6/go.mod h1:f7jQKgV5nnJpYgdEasS+/y7EsTb8ykN2z68n3TtcTaw= github.com/lestrrat-go/strftime v1.0.6/go.mod h1:f7jQKgV5nnJpYgdEasS+/y7EsTb8ykN2z68n3TtcTaw=
github.com/lithammer/shortuuid v3.0.0+incompatible h1:NcD0xWW/MZYXEHa6ITy6kaXN5nwm/V115vj2YXfhS0w= github.com/lithammer/shortuuid v3.0.0+incompatible h1:NcD0xWW/MZYXEHa6ITy6kaXN5nwm/V115vj2YXfhS0w=
github.com/lithammer/shortuuid v3.0.0+incompatible/go.mod h1:FR74pbAuElzOUuenUHTK2Tciko1/vKuIKS9dSkDrA4w= github.com/lithammer/shortuuid v3.0.0+incompatible/go.mod h1:FR74pbAuElzOUuenUHTK2Tciko1/vKuIKS9dSkDrA4w=
github.com/luhaoling/protocol v0.0.0-20231223094538-101234d675fc h1:Uj5oqXMbQDqBPnjZAjaycS0Fsf3thIjjGhYzkKDJIJk= github.com/luhaoling/protocol v0.0.0-20231223120310-24a70ff4b1c7 h1:hCfZdWHo8G5QktQR0lstItLOhi3nNhHZ2mwQS3aniVc=
github.com/luhaoling/protocol v0.0.0-20231223094538-101234d675fc/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= github.com/luhaoling/protocol v0.0.0-20231223120310-24a70ff4b1c7/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=

@ -129,10 +129,6 @@ func (m *MessageApi) SetConversationHasReadSeq(c *gin.Context) {
a2r.Call(msg.MsgClient.SetConversationHasReadSeq, m.Client, c) a2r.Call(msg.MsgClient.SetConversationHasReadSeq, m.Client, c)
} }
func (m *MessageApi) GetConversationsList(c *gin.Context) {
a2r.Call(msg.MsgClient.GetConversationList, m.Client, c)
}
func (m *MessageApi) ClearConversationsMsg(c *gin.Context) { func (m *MessageApi) ClearConversationsMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.ClearConversationsMsg, m.Client, c) a2r.Call(msg.MsgClient.ClearConversationsMsg, m.Client, c)
} }

@ -176,7 +176,6 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
msgGroup.POST("/mark_conversation_as_read", m.MarkConversationAsRead) msgGroup.POST("/mark_conversation_as_read", m.MarkConversationAsRead)
msgGroup.POST("/get_conversations_has_read_and_max_seq", m.GetConversationsHasReadAndMaxSeq) msgGroup.POST("/get_conversations_has_read_and_max_seq", m.GetConversationsHasReadAndMaxSeq)
msgGroup.POST("/set_conversation_has_read_seq", m.SetConversationHasReadSeq) msgGroup.POST("/set_conversation_has_read_seq", m.SetConversationHasReadSeq)
msgGroup.POST("/get_conversations_list", m.GetConversationsList)
msgGroup.POST("/clear_conversation_msg", m.ClearConversationsMsg) msgGroup.POST("/clear_conversation_msg", m.ClearConversationsMsg)
msgGroup.POST("/user_clear_all_msg", m.UserClearAllMsg) msgGroup.POST("/user_clear_all_msg", m.UserClearAllMsg)

@ -100,43 +100,36 @@ func (m *conversationServer) GetConversationList(ctx context.Context, req *pbcon
} else { } else {
conversationIDs = req.ConversationIDs conversationIDs = req.ConversationIDs
} }
log.ZDebug(ctx, "GetConversationList1", "seqs", req, "conversationIDs", conversationIDs)
conversations, err := m.conversationDatabase.FindConversations(ctx, req.UserID, conversationIDs) conversations, err := m.conversationDatabase.FindConversations(ctx, req.UserID, conversationIDs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.ZDebug(ctx, "GetConversationList2", "seqs", req, "conversations", conversations)
maxSeqs, err := m.msgRpcClient.GetMaxSeqs(ctx, conversationIDs) maxSeqs, err := m.msgRpcClient.GetMaxSeqs(ctx, conversationIDs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.ZDebug(ctx, "GetConversationList3", "seqs", req, "maxSeqs", maxSeqs)
chatLogs, err := m.msgRpcClient.GetMsgByConversationIDs(ctx, conversationIDs, maxSeqs) chatLogs, err := m.msgRpcClient.GetMsgByConversationIDs(ctx, conversationIDs, maxSeqs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.ZDebug(ctx, "GetConversationList4", "seqs", req, "chatLogs", chatLogs)
conversationMsg, err := m.getConversationInfo(ctx, chatLogs, req.UserID) conversationMsg, err := m.getConversationInfo(ctx, chatLogs, req.UserID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.ZDebug(ctx, "GetConversationList5", "seqs", req, "conversationMsg", conversationMsg)
hasReadSeqs, err := m.msgRpcClient.GetHasReadSeqs(ctx, req.UserID, conversationIDs) hasReadSeqs, err := m.msgRpcClient.GetHasReadSeqs(ctx, req.UserID, conversationIDs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.ZDebug(ctx, "GetConversationList6", "seqs", req, "hasReadSeqs", hasReadSeqs)
conversation_unreadCount := make(map[string]int64) conversation_unreadCount := make(map[string]int64)
for conversationID, maxSeq := range maxSeqs { for conversationID, maxSeq := range maxSeqs {
conversation_unreadCount[conversationID] = maxSeq - hasReadSeqs[conversationID] conversation_unreadCount[conversationID] = maxSeq - hasReadSeqs[conversationID]
} }
log.ZDebug(ctx, "GetConversationList7", "seqs", req, "conversation_unreadCount", conversation_unreadCount)
conversation_isPinkTime := make(map[int64]string) conversation_isPinkTime := make(map[int64]string)
conversation_notPinkTime := make(map[int64]string) conversation_notPinkTime := make(map[int64]string)
@ -154,12 +147,9 @@ func (m *conversationServer) GetConversationList(ctx context.Context, req *pbcon
resp = &pbconversation.GetConversationListResp{ resp = &pbconversation.GetConversationListResp{
ConversationElems: []*pbconversation.ConversationElem{}, ConversationElems: []*pbconversation.ConversationElem{},
} }
log.ZDebug(ctx, "GetConversationList7.1", "seqs", req, "conversation_isPinkTime", conversation_isPinkTime)
log.ZDebug(ctx, "GetConversationList7.2", "seqs", req, "conversation_notPinkTime", conversation_notPinkTime)
m.conversationSort(conversation_isPinkTime, resp, conversation_unreadCount, conversationMsg) m.conversationSort(conversation_isPinkTime, resp, conversation_unreadCount, conversationMsg)
log.ZDebug(ctx, "GetConversationList8.0", "seqs", req, "resp", resp)
m.conversationSort(conversation_notPinkTime, resp, conversation_unreadCount, conversationMsg) m.conversationSort(conversation_notPinkTime, resp, conversation_unreadCount, conversationMsg)
log.ZDebug(ctx, "GetConversationList8", "seqs", req, "resp", resp)
return resp, nil return resp, nil
} }

@ -16,10 +16,8 @@ package msg
import ( import (
"context" "context"
cbapi "github.com/openimsdk/open-im-server/v3/pkg/callbackstruct"
"sort"
utils2 "github.com/OpenIMSDK/tools/utils" utils2 "github.com/OpenIMSDK/tools/utils"
cbapi "github.com/openimsdk/open-im-server/v3/pkg/callbackstruct"
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
@ -71,69 +69,6 @@ func (m *msgServer) GetConversationsHasReadAndMaxSeq(ctx context.Context, req *m
return resp, nil return resp, nil
} }
func (m *msgServer) GetConversationList(ctx context.Context, req *msg.GetConversationListReq) (resp *msg.GetConversationListResp, err error) {
var conversationIDs []string
if len(req.ConversationIDs) == 0 {
conversationIDs, err = m.ConversationLocalCache.GetConversationIDs(ctx, req.UserID)
if err != nil {
return nil, err
}
} else {
conversationIDs = req.ConversationIDs
}
conversations, err := m.Conversation.GetConversations(ctx, req.UserID, conversationIDs)
if err != nil {
return nil, err
}
maxSeqs, err := m.MsgDatabase.GetMaxSeqs(ctx, conversationIDs)
if err != nil {
return nil, err
}
chatLogs, err := m.MsgDatabase.FindOneByDocIDs(ctx, conversationIDs, maxSeqs)
if err != nil {
return nil, err
}
conversationMsg, err := m.getConversationInfo(ctx, chatLogs, req.UserID)
if err != nil {
return nil, err
}
hasReadSeqs, err := m.MsgDatabase.GetHasReadSeqs(ctx, req.UserID, conversationIDs)
if err != nil {
return nil, err
}
conversation_unreadCount := make(map[string]int64)
for conversationID, maxSeq := range maxSeqs {
conversation_unreadCount[conversationID] = maxSeq - hasReadSeqs[conversationID]
}
conversation_isPinkTime := make(map[int64]string)
conversation_notPinkTime := 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
continue
}
conversation_notPinkTime[time] = conversationID
}
resp = &msg.GetConversationListResp{
ConversationElems: []*msg.ConversationElem{},
}
m.conversationSort(conversation_isPinkTime, resp, conversation_unreadCount, conversationMsg)
m.conversationSort(conversation_notPinkTime, resp, conversation_unreadCount, conversationMsg)
return resp, nil
}
func (m *msgServer) SetConversationHasReadSeq( func (m *msgServer) SetConversationHasReadSeq(
ctx context.Context, ctx context.Context,
req *msg.SetConversationHasReadSeqReq, req *msg.SetConversationHasReadSeqReq,
@ -288,102 +223,3 @@ func (m *msgServer) sendMarkAsReadNotification(
} }
return nil return nil
} }
func (m *msgServer) conversationSort(
conversations map[int64]string,
resp *msg.GetConversationListResp,
conversation_unreadCount map[string]int64,
conversationMsg map[string]*msg.ConversationElem,
) {
keys := []int64{}
for key := range conversations {
keys = append(keys, key)
}
sort.Slice(keys[:], func(i, j int) bool {
return keys[i] > keys[j]
})
index := 0
cons := make([]*msg.ConversationElem, len(conversations))
for _, v := range keys {
conversationID := conversations[v]
conversationElem := conversationMsg[conversationID]
conversationElem.UnreadCount = conversation_unreadCount[conversationID]
cons[index] = conversationElem
index++
}
resp.ConversationElems = append(resp.ConversationElems, cons...)
}
func (m *msgServer) getConversationInfo(
ctx context.Context,
chatLogs map[string]*sdkws.MsgData,
userID string) (map[string]*msg.ConversationElem, error) {
var (
sendIDs []string
groupIDs []string
sendMap = make(map[string]*sdkws.UserInfo)
groupMap = make(map[string]*sdkws.GroupInfo)
conversationMsg = make(map[string]*msg.ConversationElem)
)
for _, chatLog := range chatLogs {
switch chatLog.SessionType {
case constant.SingleChatType:
if chatLog.SendID == userID {
sendIDs = append(sendIDs, chatLog.RecvID)
}
sendIDs = append(sendIDs, chatLog.SendID)
case constant.GroupChatType, constant.SuperGroupChatType:
groupIDs = append(groupIDs, chatLog.GroupID)
sendIDs = append(sendIDs, chatLog.SendID)
}
}
if len(sendIDs) != 0 {
sendInfos, err := m.User.GetUsersInfo(ctx, sendIDs)
if err != nil {
return nil, err
}
for _, sendInfo := range sendInfos {
sendMap[sendInfo.UserID] = sendInfo
}
}
if len(groupIDs) != 0 {
groupInfos, err := m.Group.GetGroupInfos(ctx, groupIDs, false)
if err != nil {
return nil, err
}
for _, groupInfo := range groupInfos {
groupMap[groupInfo.GroupID] = groupInfo
}
}
for conversationID, chatLog := range chatLogs {
pbchatLog := &msg.ConversationElem{}
msgInfo := &msg.MsgInfo{}
if err := utils2.CopyStructFields(msgInfo, chatLog); err != nil {
return nil, err
}
switch chatLog.SessionType {
case constant.SingleChatType:
if chatLog.SendID == userID {
msgInfo.FaceURL = sendMap[chatLog.RecvID].FaceURL
msgInfo.SenderName = sendMap[chatLog.RecvID].Nickname
break
}
msgInfo.FaceURL = sendMap[chatLog.SendID].FaceURL
msgInfo.SenderName = sendMap[chatLog.SendID].Nickname
case constant.GroupChatType, constant.SuperGroupChatType:
msgInfo.GroupName = groupMap[chatLog.GroupID].GroupName
msgInfo.GroupFaceURL = groupMap[chatLog.GroupID].FaceURL
msgInfo.GroupMemberCount = groupMap[chatLog.GroupID].MemberCount
msgInfo.GroupID = chatLog.GroupID
msgInfo.GroupType = groupMap[chatLog.GroupID].GroupType
msgInfo.SenderName = sendMap[chatLog.SendID].Nickname
}
pbchatLog.ConversationID = conversationID
msgInfo.LatestMsgRecvTime = chatLog.SendTime
pbchatLog.MsgInfo = msgInfo
conversationMsg[conversationID] = pbchatLog
}
return conversationMsg, nil
}

Loading…
Cancel
Save