mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
parent
5615e47d99
commit
3ecd33aded
@ -116,41 +116,75 @@ func (m *msgServer) SearchMessage(ctx context.Context, req *msg.SearchMessageReq
|
|||||||
if total, chatLogs, err = m.MsgDatabase.SearchMessage(ctx, req); err != nil {
|
if total, chatLogs, err = m.MsgDatabase.SearchMessage(ctx, req); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
sendIDs []string
|
||||||
|
recvIDs []string
|
||||||
|
groupIDs []string
|
||||||
|
sendMap = make(map[string]string)
|
||||||
|
recvMap = make(map[string]string)
|
||||||
|
groupMap = make(map[string]*sdkws.GroupInfo)
|
||||||
|
)
|
||||||
|
for _, chatLog := range chatLogs {
|
||||||
|
if chatLog.SenderNickname == "" {
|
||||||
|
sendIDs = append(sendIDs, chatLog.SendID)
|
||||||
|
}
|
||||||
|
switch chatLog.SessionType {
|
||||||
|
case constant.SingleChatType:
|
||||||
|
recvIDs = append(recvIDs, chatLog.RecvID)
|
||||||
|
case constant.GroupChatType, constant.SuperGroupChatType:
|
||||||
|
groupIDs = append(groupIDs, chatLog.GroupID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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.Nickname
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(recvIDs) != 0 {
|
||||||
|
recvInfos, err := m.User.GetUsersInfo(ctx, recvIDs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, recvInfo := range recvInfos {
|
||||||
|
recvMap[recvInfo.UserID] = recvInfo.Nickname
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(groupIDs) != 0 {
|
||||||
|
groupInfos, err := m.Group.GetGroupInfos(ctx, groupIDs, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, groupInfo := range groupInfos {
|
||||||
|
groupMap[groupInfo.GroupID] = groupInfo
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, chatLog := range chatLogs {
|
for _, chatLog := range chatLogs {
|
||||||
pbChatLog := &msg.ChatLog{}
|
pbChatLog := &msg.ChatLog{}
|
||||||
utils.CopyStructFields(pbChatLog, chatLog)
|
utils.CopyStructFields(pbChatLog, chatLog)
|
||||||
pbChatLog.SendTime = chatLog.SendTime
|
pbChatLog.SendTime = chatLog.SendTime
|
||||||
pbChatLog.CreateTime = chatLog.CreateTime
|
pbChatLog.CreateTime = chatLog.CreateTime
|
||||||
if chatLog.SenderNickname == "" {
|
if chatLog.SenderNickname == "" {
|
||||||
sendUser, err := m.User.GetUserInfo(ctx, chatLog.SendID)
|
pbChatLog.SenderNickname = sendMap[chatLog.SendID]
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
pbChatLog.SenderNickname = sendUser.Nickname
|
|
||||||
}
|
}
|
||||||
switch chatLog.SessionType {
|
switch chatLog.SessionType {
|
||||||
case constant.SingleChatType:
|
case constant.SingleChatType:
|
||||||
recvUser, err := m.User.GetUserInfo(ctx, chatLog.RecvID)
|
pbChatLog.RecvNickname = recvMap[chatLog.RecvID]
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
pbChatLog.RecvNickname = recvUser.Nickname
|
|
||||||
|
|
||||||
case constant.GroupChatType, constant.SuperGroupChatType:
|
case constant.GroupChatType, constant.SuperGroupChatType:
|
||||||
group, err := m.Group.GetGroupInfo(ctx, chatLog.GroupID)
|
pbChatLog.SenderFaceURL = groupMap[chatLog.GroupID].FaceURL
|
||||||
if err != nil {
|
pbChatLog.GroupMemberCount = groupMap[chatLog.GroupID].MemberCount
|
||||||
return nil, err
|
pbChatLog.RecvID = groupMap[chatLog.GroupID].GroupID
|
||||||
}
|
pbChatLog.GroupName = groupMap[chatLog.GroupID].GroupName
|
||||||
pbChatLog.SenderFaceURL = group.FaceURL
|
pbChatLog.GroupOwner = groupMap[chatLog.GroupID].OwnerUserID
|
||||||
pbChatLog.GroupMemberCount = group.MemberCount
|
pbChatLog.GroupType = groupMap[chatLog.GroupID].GroupType
|
||||||
pbChatLog.RecvID = group.GroupID
|
|
||||||
pbChatLog.GroupName = group.GroupName
|
|
||||||
pbChatLog.GroupOwner = group.OwnerUserID
|
|
||||||
pbChatLog.GroupType = group.GroupType
|
|
||||||
}
|
}
|
||||||
resp.ChatLogs = append(resp.ChatLogs, pbChatLog)
|
resp.ChatLogs = append(resp.ChatLogs, pbChatLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.ChatLogsNum = total
|
resp.ChatLogsNum = total
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
@ -962,6 +962,9 @@ func (db *commonMsgDatabase) SearchMessage(ctx context.Context, req *pbMsg.Searc
|
|||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
for _, msg := range msgs {
|
for _, msg := range msgs {
|
||||||
|
if msg.IsRead {
|
||||||
|
msg.Msg.IsRead = true
|
||||||
|
}
|
||||||
totalMsgs = append(totalMsgs, convert.MsgDB2Pb(msg.Msg))
|
totalMsgs = append(totalMsgs, convert.MsgDB2Pb(msg.Msg))
|
||||||
}
|
}
|
||||||
return total, totalMsgs, nil
|
return total, totalMsgs, nil
|
||||||
|
@ -1073,11 +1073,6 @@ func (m *MsgMongoDriver) SearchMessage(ctx context.Context, req *msg.SearchMessa
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
for _, msg1 := range msgs {
|
|
||||||
if msg1.IsRead {
|
|
||||||
msg1.Msg.IsRead = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return total, msgs, nil
|
return total, msgs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1151,13 +1146,22 @@ func (m *MsgMongoDriver) searchMessage(ctx context.Context, req *msg.SearchMessa
|
|||||||
{"doc_id", 1},
|
{"doc_id", 1},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
{"$unwind", bson.M{"path": "$msgs"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{"$sort", bson.M{"msgs.msg.send_time": -1}},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
cursor, err := m.MsgCollection.Aggregate(ctx, pipe)
|
cursor, err := m.MsgCollection.Aggregate(ctx, pipe)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
|
type docModel struct {
|
||||||
var msgsDocs []table.MsgDocModel
|
DocID string `bson:"doc_id"`
|
||||||
|
Msg *table.MsgInfoModel `bson:"msgs"`
|
||||||
|
}
|
||||||
|
var msgsDocs []docModel
|
||||||
err = cursor.All(ctx, &msgsDocs)
|
err = cursor.All(ctx, &msgsDocs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
@ -1167,41 +1171,39 @@ func (m *MsgMongoDriver) searchMessage(ctx context.Context, req *msg.SearchMessa
|
|||||||
}
|
}
|
||||||
msgs := make([]*table.MsgInfoModel, 0)
|
msgs := make([]*table.MsgInfoModel, 0)
|
||||||
for index := range msgsDocs {
|
for index := range msgsDocs {
|
||||||
for i := range msgsDocs[index].Msg {
|
msgInfo := msgsDocs[index].Msg
|
||||||
msg := msgsDocs[index].Msg[i]
|
if msgInfo == nil || msgInfo.Msg == nil {
|
||||||
if msg == nil || msg.Msg == nil {
|
continue
|
||||||
continue
|
|
||||||
}
|
|
||||||
if msg.Revoke != nil {
|
|
||||||
revokeContent := sdkws.MessageRevokedContent{
|
|
||||||
RevokerID: msg.Revoke.UserID,
|
|
||||||
RevokerRole: msg.Revoke.Role,
|
|
||||||
ClientMsgID: msg.Msg.ClientMsgID,
|
|
||||||
RevokerNickname: msg.Revoke.Nickname,
|
|
||||||
RevokeTime: msg.Revoke.Time,
|
|
||||||
SourceMessageSendTime: msg.Msg.SendTime,
|
|
||||||
SourceMessageSendID: msg.Msg.SendID,
|
|
||||||
SourceMessageSenderNickname: msg.Msg.SenderNickname,
|
|
||||||
SessionType: msg.Msg.SessionType,
|
|
||||||
Seq: msg.Msg.Seq,
|
|
||||||
Ex: msg.Msg.Ex,
|
|
||||||
}
|
|
||||||
data, err := json.Marshal(&revokeContent)
|
|
||||||
if err != nil {
|
|
||||||
return 0, nil, err
|
|
||||||
}
|
|
||||||
elem := sdkws.NotificationElem{
|
|
||||||
Detail: string(data),
|
|
||||||
}
|
|
||||||
content, err := json.Marshal(&elem)
|
|
||||||
if err != nil {
|
|
||||||
return 0, nil, err
|
|
||||||
}
|
|
||||||
msg.Msg.ContentType = constant.MsgRevokeNotification
|
|
||||||
msg.Msg.Content = string(content)
|
|
||||||
}
|
|
||||||
msgs = append(msgs, msg)
|
|
||||||
}
|
}
|
||||||
|
if msgInfo.Revoke != nil {
|
||||||
|
revokeContent := sdkws.MessageRevokedContent{
|
||||||
|
RevokerID: msgInfo.Revoke.UserID,
|
||||||
|
RevokerRole: msgInfo.Revoke.Role,
|
||||||
|
ClientMsgID: msgInfo.Msg.ClientMsgID,
|
||||||
|
RevokerNickname: msgInfo.Revoke.Nickname,
|
||||||
|
RevokeTime: msgInfo.Revoke.Time,
|
||||||
|
SourceMessageSendTime: msgInfo.Msg.SendTime,
|
||||||
|
SourceMessageSendID: msgInfo.Msg.SendID,
|
||||||
|
SourceMessageSenderNickname: msgInfo.Msg.SenderNickname,
|
||||||
|
SessionType: msgInfo.Msg.SessionType,
|
||||||
|
Seq: msgInfo.Msg.Seq,
|
||||||
|
Ex: msgInfo.Msg.Ex,
|
||||||
|
}
|
||||||
|
data, err := json.Marshal(&revokeContent)
|
||||||
|
if err != nil {
|
||||||
|
return 0, nil, err
|
||||||
|
}
|
||||||
|
elem := sdkws.NotificationElem{
|
||||||
|
Detail: string(data),
|
||||||
|
}
|
||||||
|
content, err := json.Marshal(&elem)
|
||||||
|
if err != nil {
|
||||||
|
return 0, nil, err
|
||||||
|
}
|
||||||
|
msgInfo.Msg.ContentType = constant.MsgRevokeNotification
|
||||||
|
msgInfo.Msg.Content = string(content)
|
||||||
|
}
|
||||||
|
msgs = append(msgs, msgInfo)
|
||||||
}
|
}
|
||||||
start := (req.Pagination.PageNumber - 1) * req.Pagination.ShowNumber
|
start := (req.Pagination.PageNumber - 1) * req.Pagination.ShowNumber
|
||||||
n := int32(len(msgs))
|
n := int32(len(msgs))
|
||||||
|
12
scripts/start.bat
Normal file
12
scripts/start.bat
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
cd %~p0../_output/bin/platforms/windows
|
||||||
|
start api.exe -p 10002
|
||||||
|
start auth.exe -p 10060
|
||||||
|
start conversation.exe -p 10080
|
||||||
|
start friend.exe -p 10020
|
||||||
|
start group.exe -p 10050
|
||||||
|
start msg.exe -p 10030
|
||||||
|
start msggateway.exe -p 10040 -w 10001
|
||||||
|
start msgtransfer.exe
|
||||||
|
start third.exe -p 10090
|
||||||
|
start push.exe -p 10070
|
||||||
|
start user.exe -p 10010
|
Loading…
x
Reference in New Issue
Block a user