mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-01-07 12:17:02 +08:00
modify searchmessage
Signed-off-by: hanzhixiao <709674996@qq.com>
This commit is contained in:
parent
f592a3abd7
commit
88b91ab15f
@ -361,3 +361,7 @@ func (m *MessageApi) GetActiveGroup(c *gin.Context) {
|
||||
func (m *MessageApi) SearchMsg(c *gin.Context) {
|
||||
a2r.Call(msg.MsgClient.SearchMessage, m.Client, c)
|
||||
}
|
||||
|
||||
//func (m *MessageApi) OnlineUserCount(c *gin.Context) {
|
||||
// a2r.Call(msg.MsgClient, m.Client, c)
|
||||
//}
|
||||
|
||||
@ -201,6 +201,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
|
||||
statisticsGroup.POST("/user/active", m.GetActiveUser)
|
||||
statisticsGroup.POST("/group/create", g.GroupCreateCount)
|
||||
statisticsGroup.POST("/group/active", m.GetActiveGroup)
|
||||
//statisticsGroup.POST("/user/online", m.OnlineUserCount)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
@ -115,41 +115,75 @@ func (m *msgServer) SearchMessage(ctx context.Context, req *msg.SearchMessageReq
|
||||
if total, chatLogs, err = m.MsgDatabase.SearchMessage(ctx, req); err != nil {
|
||||
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 {
|
||||
pbChatLog := &msg.ChatLog{}
|
||||
utils.CopyStructFields(pbChatLog, chatLog)
|
||||
pbChatLog.SendTime = chatLog.SendTime
|
||||
pbChatLog.CreateTime = chatLog.CreateTime
|
||||
if chatLog.SenderNickname == "" {
|
||||
sendUser, err := m.User.GetUserInfo(ctx, chatLog.SendID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbChatLog.SenderNickname = sendUser.Nickname
|
||||
pbChatLog.SenderNickname = sendMap[chatLog.SendID]
|
||||
}
|
||||
switch chatLog.SessionType {
|
||||
case constant.SingleChatType:
|
||||
recvUser, err := m.User.GetUserInfo(ctx, chatLog.RecvID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbChatLog.RecvNickname = recvUser.Nickname
|
||||
pbChatLog.RecvNickname = recvMap[chatLog.RecvID]
|
||||
|
||||
case constant.GroupChatType, constant.SuperGroupChatType:
|
||||
group, err := m.Group.GetGroupInfo(ctx, chatLog.GroupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbChatLog.SenderFaceURL = group.FaceURL
|
||||
pbChatLog.GroupMemberCount = group.MemberCount
|
||||
pbChatLog.RecvID = group.GroupID
|
||||
pbChatLog.GroupName = group.GroupName
|
||||
pbChatLog.GroupOwner = group.OwnerUserID
|
||||
pbChatLog.GroupType = group.GroupType
|
||||
pbChatLog.SenderFaceURL = groupMap[chatLog.GroupID].FaceURL
|
||||
pbChatLog.GroupMemberCount = groupMap[chatLog.GroupID].MemberCount
|
||||
pbChatLog.RecvID = groupMap[chatLog.GroupID].GroupID
|
||||
pbChatLog.GroupName = groupMap[chatLog.GroupID].GroupName
|
||||
pbChatLog.GroupOwner = groupMap[chatLog.GroupID].OwnerUserID
|
||||
pbChatLog.GroupType = groupMap[chatLog.GroupID].GroupType
|
||||
}
|
||||
resp.ChatLogs = append(resp.ChatLogs, pbChatLog)
|
||||
}
|
||||
|
||||
resp.ChatLogsNum = total
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@ -44,3 +44,7 @@ func (s *userServer) UserRegisterCount(
|
||||
}
|
||||
return &pbuser.UserRegisterCountResp{Total: total, Before: before, Count: count}, nil
|
||||
}
|
||||
|
||||
//func (s *userServer) OnlineUserCount(ctx context.Context) error {
|
||||
// s.
|
||||
//}
|
||||
|
||||
@ -960,6 +960,9 @@ func (db *commonMsgDatabase) SearchMessage(ctx context.Context, req *pbMsg.Searc
|
||||
return 0, nil, err
|
||||
}
|
||||
for _, msg := range msgs {
|
||||
if msg.IsRead {
|
||||
msg.Msg.IsRead = true
|
||||
}
|
||||
totalMsgs = append(totalMsgs, convert.MsgDB2Pb(msg.Msg))
|
||||
}
|
||||
return total, totalMsgs, nil
|
||||
|
||||
@ -61,6 +61,8 @@ type UserDatabase interface {
|
||||
GetUserStatus(ctx context.Context, userIDs []string) ([]*user.OnlineStatus, error)
|
||||
// SetUserStatus Set the user status and store the user status in redis
|
||||
SetUserStatus(ctx context.Context, list []*user.OnlineStatus) error
|
||||
|
||||
//OnlineUserCount(ctx context.Context, start time.Time, end time.Time) (int64, map[string]int64, error)
|
||||
}
|
||||
|
||||
type userDatabase struct {
|
||||
@ -176,7 +178,7 @@ func (u *userDatabase) CountRangeEverydayTotal(ctx context.Context, start time.T
|
||||
return u.userDB.CountRangeEverydayTotal(ctx, start, end)
|
||||
}
|
||||
|
||||
//SubscribeOrCancelUsersStatus Subscribe or unsubscribe a user's presence status
|
||||
// SubscribeOrCancelUsersStatus Subscribe or unsubscribe a user's presence status
|
||||
func (u *userDatabase) SubscribeOrCancelUsersStatus(ctx context.Context, userID string, userIDs []string, genre int32) error {
|
||||
var err error
|
||||
if genre == constant.SubscriberUser {
|
||||
|
||||
@ -1072,11 +1072,6 @@ func (m *MsgMongoDriver) SearchMessage(ctx context.Context, req *msg.SearchMessa
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
for _, msg1 := range msgs {
|
||||
if msg1.IsRead {
|
||||
msg1.Msg.IsRead = true
|
||||
}
|
||||
}
|
||||
return total, msgs, nil
|
||||
}
|
||||
|
||||
@ -1150,13 +1145,22 @@ func (m *MsgMongoDriver) searchMessage(ctx context.Context, req *msg.SearchMessa
|
||||
{"doc_id", 1},
|
||||
}},
|
||||
},
|
||||
{
|
||||
{"$unwind", bson.M{"path": "$msgs"}},
|
||||
},
|
||||
{
|
||||
{"$sort", bson.M{"msgs.msg.send_time": -1}},
|
||||
},
|
||||
}
|
||||
cursor, err := m.MsgCollection.Aggregate(ctx, pipe)
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
|
||||
var msgsDocs []table.MsgDocModel
|
||||
type docModel struct {
|
||||
DocID string `bson:"doc_id"`
|
||||
Msg *table.MsgInfoModel `bson:"msgs"`
|
||||
}
|
||||
var msgsDocs []docModel
|
||||
err = cursor.All(ctx, &msgsDocs)
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
@ -1166,41 +1170,39 @@ func (m *MsgMongoDriver) searchMessage(ctx context.Context, req *msg.SearchMessa
|
||||
}
|
||||
msgs := make([]*table.MsgInfoModel, 0)
|
||||
for index := range msgsDocs {
|
||||
for i := range msgsDocs[index].Msg {
|
||||
msg := msgsDocs[index].Msg[i]
|
||||
if msg == nil || msg.Msg == nil {
|
||||
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)
|
||||
msgInfo := msgsDocs[index].Msg
|
||||
if msgInfo == nil || msgInfo.Msg == nil {
|
||||
continue
|
||||
}
|
||||
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
|
||||
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