|
|
|
@ -16,6 +16,7 @@ package msg
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor"
|
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/util/conversationutil"
|
|
|
|
@ -144,7 +145,8 @@ func (m *msgServer) GetMaxSeq(ctx context.Context, req *sdkws.GetMaxSeqReq) (*sd
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *msgServer) SearchMessage(ctx context.Context, req *msg.SearchMessageReq) (resp *msg.SearchMessageResp, err error) {
|
|
|
|
|
var chatLogs []*sdkws.MsgData
|
|
|
|
|
// var chatLogs []*sdkws.MsgData
|
|
|
|
|
var chatLogs []*msg.SearchedMsgData
|
|
|
|
|
var total int64
|
|
|
|
|
resp = &msg.SearchMessageResp{}
|
|
|
|
|
if total, chatLogs, err = m.MsgDatabase.SearchMessage(ctx, req); err != nil {
|
|
|
|
@ -159,17 +161,19 @@ func (m *msgServer) SearchMessage(ctx context.Context, req *msg.SearchMessageReq
|
|
|
|
|
recvMap = make(map[string]string)
|
|
|
|
|
groupMap = make(map[string]*sdkws.GroupInfo)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
for _, chatLog := range chatLogs {
|
|
|
|
|
if chatLog.SenderNickname == "" {
|
|
|
|
|
sendIDs = append(sendIDs, chatLog.SendID)
|
|
|
|
|
if chatLog.MsgData.SenderNickname == "" {
|
|
|
|
|
sendIDs = append(sendIDs, chatLog.MsgData.SendID)
|
|
|
|
|
}
|
|
|
|
|
switch chatLog.SessionType {
|
|
|
|
|
switch chatLog.MsgData.SessionType {
|
|
|
|
|
case constant.SingleChatType, constant.NotificationChatType:
|
|
|
|
|
recvIDs = append(recvIDs, chatLog.RecvID)
|
|
|
|
|
recvIDs = append(recvIDs, chatLog.MsgData.RecvID)
|
|
|
|
|
case constant.WriteGroupChatType, constant.ReadGroupChatType:
|
|
|
|
|
groupIDs = append(groupIDs, chatLog.GroupID)
|
|
|
|
|
groupIDs = append(groupIDs, chatLog.MsgData.GroupID)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Retrieve sender and receiver information
|
|
|
|
|
if len(sendIDs) != 0 {
|
|
|
|
|
sendInfos, err := m.UserLocalCache.GetUsersInfo(ctx, sendIDs)
|
|
|
|
@ -180,6 +184,7 @@ func (m *msgServer) SearchMessage(ctx context.Context, req *msg.SearchMessageReq
|
|
|
|
|
sendMap[sendInfo.UserID] = sendInfo.Nickname
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(recvIDs) != 0 {
|
|
|
|
|
recvInfos, err := m.UserLocalCache.GetUsersInfo(ctx, recvIDs)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -205,20 +210,21 @@ func (m *msgServer) SearchMessage(ctx context.Context, req *msg.SearchMessageReq
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Construct response with updated information
|
|
|
|
|
for _, chatLog := range chatLogs {
|
|
|
|
|
pbchatLog := &msg.ChatLog{}
|
|
|
|
|
datautil.CopyStructFields(pbchatLog, chatLog)
|
|
|
|
|
pbchatLog.SendTime = chatLog.SendTime
|
|
|
|
|
pbchatLog.CreateTime = chatLog.CreateTime
|
|
|
|
|
if chatLog.SenderNickname == "" {
|
|
|
|
|
pbchatLog.SenderNickname = sendMap[chatLog.SendID]
|
|
|
|
|
datautil.CopyStructFields(pbchatLog, chatLog.MsgData)
|
|
|
|
|
pbchatLog.SendTime = chatLog.MsgData.SendTime
|
|
|
|
|
pbchatLog.CreateTime = chatLog.MsgData.CreateTime
|
|
|
|
|
if chatLog.MsgData.SenderNickname == "" {
|
|
|
|
|
pbchatLog.SenderNickname = sendMap[chatLog.MsgData.SendID]
|
|
|
|
|
}
|
|
|
|
|
switch chatLog.SessionType {
|
|
|
|
|
switch chatLog.MsgData.SessionType {
|
|
|
|
|
case constant.SingleChatType, constant.NotificationChatType:
|
|
|
|
|
pbchatLog.RecvNickname = recvMap[chatLog.RecvID]
|
|
|
|
|
case constant.WriteGroupChatType, constant.ReadGroupChatType:
|
|
|
|
|
groupInfo := groupMap[chatLog.GroupID]
|
|
|
|
|
pbchatLog.RecvNickname = recvMap[chatLog.MsgData.RecvID]
|
|
|
|
|
case constant.ReadGroupChatType:
|
|
|
|
|
groupInfo := groupMap[chatLog.MsgData.GroupID]
|
|
|
|
|
pbchatLog.SenderFaceURL = groupInfo.FaceURL
|
|
|
|
|
pbchatLog.GroupMemberCount = groupInfo.MemberCount // Reflects actual member count
|
|
|
|
|
pbchatLog.RecvID = groupInfo.GroupID
|
|
|
|
@ -226,7 +232,9 @@ func (m *msgServer) SearchMessage(ctx context.Context, req *msg.SearchMessageReq
|
|
|
|
|
pbchatLog.GroupOwner = groupInfo.OwnerUserID
|
|
|
|
|
pbchatLog.GroupType = groupInfo.GroupType
|
|
|
|
|
}
|
|
|
|
|
resp.ChatLogs = append(resp.ChatLogs, pbchatLog)
|
|
|
|
|
searchChatLog := &msg.SearchChatLog{ChatLog: pbchatLog, IsRevoked: chatLog.IsRevoked}
|
|
|
|
|
|
|
|
|
|
resp.ChatLogs = append(resp.ChatLogs, searchChatLog)
|
|
|
|
|
}
|
|
|
|
|
resp.ChatLogsNum = int32(total)
|
|
|
|
|
return resp, nil
|
|
|
|
|