mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 15:52:27 +08:00
修改聊天数据查询条件
This commit is contained in:
@@ -246,14 +246,29 @@ func (d *Dao) QueryChatMsgList() ([]*model.ChatMsg, error) {
|
||||
|
||||
func (d *Dao) QueryChatMsgListByUid(uid uint32) ([]*model.ChatMsg, error) {
|
||||
db := d.db.Collection("chat_msg")
|
||||
result := make([]*model.ChatMsg, 0)
|
||||
find, err := db.Find(
|
||||
context.TODO(),
|
||||
bson.D{{"ToUid", uid}, {"Uid", uid}},
|
||||
bson.D{{"ToUid", uid}},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for find.Next(context.TODO()) {
|
||||
item := new(model.ChatMsg)
|
||||
err = find.Decode(item)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result = append(result, item)
|
||||
}
|
||||
find, err = db.Find(
|
||||
context.TODO(),
|
||||
bson.D{{"Uid", uid}},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]*model.ChatMsg, 0)
|
||||
for find.Next(context.TODO()) {
|
||||
item := new(model.ChatMsg)
|
||||
err = find.Decode(item)
|
||||
|
||||
@@ -470,15 +470,25 @@ func (u *UserManager) LoadUserChatMsgFromDbSync(userId uint32) map[uint32][]*mod
|
||||
return chatMsgMap
|
||||
}
|
||||
for _, chatMsg := range chatMsgList {
|
||||
msgList, exist := chatMsgMap[chatMsg.ToUid]
|
||||
otherUid := uint32(0)
|
||||
if chatMsg.Uid == userId {
|
||||
otherUid = chatMsg.ToUid
|
||||
} else if chatMsg.ToUid == userId {
|
||||
otherUid = chatMsg.Uid
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
msgList, exist := chatMsgMap[otherUid]
|
||||
if !exist {
|
||||
msgList = make([]*model.ChatMsg, 0)
|
||||
}
|
||||
if len(msgList) > MaxMsgListLen {
|
||||
continue
|
||||
}
|
||||
msgList = append(msgList, chatMsg)
|
||||
chatMsgMap[chatMsg.ToUid] = msgList
|
||||
chatMsgMap[otherUid] = msgList
|
||||
}
|
||||
for otherUid, msgList := range chatMsgMap {
|
||||
if len(msgList) > MaxMsgListLen {
|
||||
chatMsgMap[otherUid] = msgList[len(msgList)-MaxMsgListLen:]
|
||||
}
|
||||
}
|
||||
return chatMsgMap
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user