mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-04-29 18:34:04 +08:00
Merge 6e7bfbea8e3506dd03cce1fab90e95b8281eba57 into 5211d43d9d86772a45b451e49d526400a4e0448e
This commit is contained in:
commit
f65c6d6d57
@ -233,9 +233,28 @@ func (c *conversationServer) getConversations(ctx context.Context, ownerUserID s
|
||||
|
||||
// Deprecated
|
||||
func (c *conversationServer) SetConversation(ctx context.Context, req *pbconversation.SetConversationReq) (*pbconversation.SetConversationResp, error) {
|
||||
if req.Conversation == nil {
|
||||
return nil, errs.ErrArgs.WrapMsg("conversation must not be nil")
|
||||
}
|
||||
var conversation dbModel.Conversation
|
||||
if err := datautil.CopyStructFields(&conversation, req.Conversation); err != nil {
|
||||
return nil, err
|
||||
conversation.OwnerUserID = req.Conversation.OwnerUserID
|
||||
conversation.ConversationID = req.Conversation.ConversationID
|
||||
conversation.RecvMsgOpt = req.Conversation.RecvMsgOpt
|
||||
conversation.ConversationType = req.Conversation.ConversationType
|
||||
conversation.UserID = req.Conversation.UserID
|
||||
conversation.GroupID = req.Conversation.GroupID
|
||||
conversation.IsPinned = req.Conversation.IsPinned
|
||||
conversation.AttachedInfo = req.Conversation.AttachedInfo
|
||||
conversation.IsPrivateChat = req.Conversation.IsPrivateChat
|
||||
conversation.GroupAtType = req.Conversation.GroupAtType
|
||||
conversation.Ex = req.Conversation.Ex
|
||||
conversation.BurnDuration = req.Conversation.BurnDuration
|
||||
conversation.MinSeq = req.Conversation.MinSeq
|
||||
conversation.MaxSeq = req.Conversation.MaxSeq
|
||||
conversation.MsgDestructTime = req.Conversation.MsgDestructTime
|
||||
conversation.IsMsgDestruct = req.Conversation.IsMsgDestruct
|
||||
if req.Conversation.LatestMsgDestructTime != 0 {
|
||||
conversation.LatestMsgDestructTime = time.UnixMilli(req.Conversation.LatestMsgDestructTime)
|
||||
}
|
||||
err := c.conversationDatabase.SetUserConversations(ctx, req.Conversation.OwnerUserID, []*dbModel.Conversation{&conversation})
|
||||
if err != nil {
|
||||
@ -606,9 +625,17 @@ func (c *conversationServer) getConversationInfo(
|
||||
}
|
||||
for conversationID, chatLog := range chatLogs {
|
||||
pbchatLog := &pbconversation.ConversationElem{}
|
||||
msgInfo := &pbconversation.MsgInfo{}
|
||||
if err := datautil.CopyStructFields(msgInfo, chatLog); err != nil {
|
||||
return nil, err
|
||||
msgInfo := &pbconversation.MsgInfo{
|
||||
ServerMsgID: chatLog.ServerMsgID,
|
||||
ClientMsgID: chatLog.ClientMsgID,
|
||||
SessionType: chatLog.SessionType,
|
||||
SendID: chatLog.SendID,
|
||||
RecvID: chatLog.RecvID,
|
||||
GroupID: chatLog.GroupID,
|
||||
MsgFrom: chatLog.MsgFrom,
|
||||
ContentType: chatLog.ContentType,
|
||||
Content: string(chatLog.Content),
|
||||
Ex: chatLog.Ex,
|
||||
}
|
||||
switch chatLog.SessionType {
|
||||
case constant.SingleChatType:
|
||||
|
||||
@ -24,7 +24,6 @@ import (
|
||||
"github.com/openimsdk/protocol/msg"
|
||||
"github.com/openimsdk/protocol/sdkws"
|
||||
"github.com/openimsdk/tools/log"
|
||||
"github.com/openimsdk/tools/utils/datautil"
|
||||
"github.com/openimsdk/tools/utils/timeutil"
|
||||
)
|
||||
|
||||
@ -216,9 +215,24 @@ 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.MsgData)
|
||||
pbchatLog.SendTime = chatLog.MsgData.SendTime
|
||||
pbchatLog.CreateTime = chatLog.MsgData.CreateTime
|
||||
msgData := chatLog.MsgData
|
||||
pbchatLog.ServerMsgID = msgData.ServerMsgID
|
||||
pbchatLog.ClientMsgID = msgData.ClientMsgID
|
||||
pbchatLog.SendID = msgData.SendID
|
||||
pbchatLog.RecvID = msgData.RecvID
|
||||
pbchatLog.GroupID = msgData.GroupID
|
||||
pbchatLog.SenderPlatformID = msgData.SenderPlatformID
|
||||
pbchatLog.SenderNickname = msgData.SenderNickname
|
||||
pbchatLog.SenderFaceURL = msgData.SenderFaceURL
|
||||
pbchatLog.SessionType = msgData.SessionType
|
||||
pbchatLog.MsgFrom = msgData.MsgFrom
|
||||
pbchatLog.ContentType = msgData.ContentType
|
||||
pbchatLog.Content = string(msgData.Content)
|
||||
pbchatLog.Status = msgData.Status
|
||||
pbchatLog.SendTime = msgData.SendTime
|
||||
pbchatLog.CreateTime = msgData.CreateTime
|
||||
pbchatLog.Ex = msgData.Ex
|
||||
pbchatLog.Seq = msgData.Seq
|
||||
if chatLog.MsgData.SenderNickname == "" {
|
||||
pbchatLog.SenderNickname = sendMap[chatLog.MsgData.SendID]
|
||||
}
|
||||
|
||||
@ -15,46 +15,120 @@
|
||||
package convert
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
||||
"github.com/openimsdk/protocol/conversation"
|
||||
"github.com/openimsdk/tools/utils/datautil"
|
||||
)
|
||||
|
||||
func ConversationDB2Pb(conversationDB *model.Conversation) *conversation.Conversation {
|
||||
conversationPB := &conversation.Conversation{}
|
||||
conversationPB.LatestMsgDestructTime = conversationDB.LatestMsgDestructTime.UnixMilli()
|
||||
if err := datautil.CopyStructFields(conversationPB, conversationDB); err != nil {
|
||||
if conversationDB == nil {
|
||||
return nil
|
||||
}
|
||||
return conversationPB
|
||||
return &conversation.Conversation{
|
||||
OwnerUserID: conversationDB.OwnerUserID,
|
||||
ConversationID: conversationDB.ConversationID,
|
||||
RecvMsgOpt: conversationDB.RecvMsgOpt,
|
||||
ConversationType: conversationDB.ConversationType,
|
||||
UserID: conversationDB.UserID,
|
||||
GroupID: conversationDB.GroupID,
|
||||
IsPinned: conversationDB.IsPinned,
|
||||
AttachedInfo: conversationDB.AttachedInfo,
|
||||
IsPrivateChat: conversationDB.IsPrivateChat,
|
||||
GroupAtType: conversationDB.GroupAtType,
|
||||
Ex: conversationDB.Ex,
|
||||
BurnDuration: conversationDB.BurnDuration,
|
||||
MinSeq: conversationDB.MinSeq,
|
||||
MaxSeq: conversationDB.MaxSeq,
|
||||
MsgDestructTime: conversationDB.MsgDestructTime,
|
||||
LatestMsgDestructTime: conversationDB.LatestMsgDestructTime.UnixMilli(),
|
||||
IsMsgDestruct: conversationDB.IsMsgDestruct,
|
||||
}
|
||||
}
|
||||
|
||||
func ConversationsDB2Pb(conversationsDB []*model.Conversation) (conversationsPB []*conversation.Conversation) {
|
||||
for _, conversationDB := range conversationsDB {
|
||||
conversationPB := &conversation.Conversation{}
|
||||
if err := datautil.CopyStructFields(conversationPB, conversationDB); err != nil {
|
||||
if conversationDB == nil {
|
||||
continue
|
||||
}
|
||||
conversationPB.LatestMsgDestructTime = conversationDB.LatestMsgDestructTime.UnixMilli()
|
||||
conversationPB := &conversation.Conversation{
|
||||
OwnerUserID: conversationDB.OwnerUserID,
|
||||
ConversationID: conversationDB.ConversationID,
|
||||
RecvMsgOpt: conversationDB.RecvMsgOpt,
|
||||
ConversationType: conversationDB.ConversationType,
|
||||
UserID: conversationDB.UserID,
|
||||
GroupID: conversationDB.GroupID,
|
||||
IsPinned: conversationDB.IsPinned,
|
||||
AttachedInfo: conversationDB.AttachedInfo,
|
||||
IsPrivateChat: conversationDB.IsPrivateChat,
|
||||
GroupAtType: conversationDB.GroupAtType,
|
||||
Ex: conversationDB.Ex,
|
||||
BurnDuration: conversationDB.BurnDuration,
|
||||
MinSeq: conversationDB.MinSeq,
|
||||
MaxSeq: conversationDB.MaxSeq,
|
||||
MsgDestructTime: conversationDB.MsgDestructTime,
|
||||
LatestMsgDestructTime: conversationDB.LatestMsgDestructTime.UnixMilli(),
|
||||
IsMsgDestruct: conversationDB.IsMsgDestruct,
|
||||
}
|
||||
conversationsPB = append(conversationsPB, conversationPB)
|
||||
}
|
||||
return conversationsPB
|
||||
}
|
||||
|
||||
func ConversationPb2DB(conversationPB *conversation.Conversation) *model.Conversation {
|
||||
conversationDB := &model.Conversation{}
|
||||
if err := datautil.CopyStructFields(conversationDB, conversationPB); err != nil {
|
||||
if conversationPB == nil {
|
||||
return nil
|
||||
}
|
||||
conversationDB := &model.Conversation{
|
||||
OwnerUserID: conversationPB.OwnerUserID,
|
||||
ConversationID: conversationPB.ConversationID,
|
||||
RecvMsgOpt: conversationPB.RecvMsgOpt,
|
||||
ConversationType: conversationPB.ConversationType,
|
||||
UserID: conversationPB.UserID,
|
||||
GroupID: conversationPB.GroupID,
|
||||
IsPinned: conversationPB.IsPinned,
|
||||
AttachedInfo: conversationPB.AttachedInfo,
|
||||
IsPrivateChat: conversationPB.IsPrivateChat,
|
||||
GroupAtType: conversationPB.GroupAtType,
|
||||
Ex: conversationPB.Ex,
|
||||
BurnDuration: conversationPB.BurnDuration,
|
||||
MinSeq: conversationPB.MinSeq,
|
||||
MaxSeq: conversationPB.MaxSeq,
|
||||
MsgDestructTime: conversationPB.MsgDestructTime,
|
||||
IsMsgDestruct: conversationPB.IsMsgDestruct,
|
||||
}
|
||||
if conversationPB.LatestMsgDestructTime != 0 {
|
||||
conversationDB.LatestMsgDestructTime = time.UnixMilli(conversationPB.LatestMsgDestructTime)
|
||||
}
|
||||
return conversationDB
|
||||
}
|
||||
|
||||
func ConversationsPb2DB(conversationsPB []*conversation.Conversation) (conversationsDB []*model.Conversation) {
|
||||
for _, conversationPB := range conversationsPB {
|
||||
conversationDB := &model.Conversation{}
|
||||
if err := datautil.CopyStructFields(conversationDB, conversationPB); err != nil {
|
||||
if conversationPB == nil {
|
||||
continue
|
||||
}
|
||||
conversationDB := &model.Conversation{
|
||||
OwnerUserID: conversationPB.OwnerUserID,
|
||||
ConversationID: conversationPB.ConversationID,
|
||||
RecvMsgOpt: conversationPB.RecvMsgOpt,
|
||||
ConversationType: conversationPB.ConversationType,
|
||||
UserID: conversationPB.UserID,
|
||||
GroupID: conversationPB.GroupID,
|
||||
IsPinned: conversationPB.IsPinned,
|
||||
AttachedInfo: conversationPB.AttachedInfo,
|
||||
IsPrivateChat: conversationPB.IsPrivateChat,
|
||||
GroupAtType: conversationPB.GroupAtType,
|
||||
Ex: conversationPB.Ex,
|
||||
BurnDuration: conversationPB.BurnDuration,
|
||||
MinSeq: conversationPB.MinSeq,
|
||||
MaxSeq: conversationPB.MaxSeq,
|
||||
MsgDestructTime: conversationPB.MsgDestructTime,
|
||||
IsMsgDestruct: conversationPB.IsMsgDestruct,
|
||||
}
|
||||
if conversationPB.LatestMsgDestructTime != 0 {
|
||||
conversationDB.LatestMsgDestructTime = time.UnixMilli(conversationPB.LatestMsgDestructTime)
|
||||
}
|
||||
conversationsDB = append(conversationsDB, conversationDB)
|
||||
}
|
||||
return conversationsDB
|
||||
|
||||
@ -21,18 +21,22 @@ import (
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/notification/common_user"
|
||||
"github.com/openimsdk/protocol/relation"
|
||||
|
||||
"github.com/openimsdk/protocol/sdkws"
|
||||
"github.com/openimsdk/tools/utils/datautil"
|
||||
"github.com/openimsdk/tools/utils/timeutil"
|
||||
)
|
||||
|
||||
func FriendPb2DB(friend *sdkws.FriendInfo) *model.Friend {
|
||||
dbFriend := &model.Friend{}
|
||||
err := datautil.CopyStructFields(dbFriend, friend)
|
||||
if err != nil {
|
||||
if friend == nil {
|
||||
return nil
|
||||
}
|
||||
dbFriend := &model.Friend{}
|
||||
dbFriend.OwnerUserID = friend.OwnerUserID
|
||||
dbFriend.Remark = friend.Remark
|
||||
dbFriend.AddSource = friend.AddSource
|
||||
dbFriend.OperatorUserID = friend.OperatorUserID
|
||||
dbFriend.Ex = friend.Ex
|
||||
dbFriend.IsPinned = friend.IsPinned
|
||||
dbFriend.FriendUserID = friend.FriendUser.UserID
|
||||
dbFriend.CreateTime = timeutil.UnixSecondToTime(friend.CreateTime)
|
||||
return dbFriend
|
||||
@ -69,10 +73,12 @@ func FriendsDB2Pb(ctx context.Context, friendsDB []*model.Friend, getUsers func(
|
||||
}
|
||||
for _, friend := range friendsDB {
|
||||
friendPb := &sdkws.FriendInfo{FriendUser: &sdkws.UserInfo{}}
|
||||
err := datautil.CopyStructFields(friendPb, friend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
friendPb.OwnerUserID = friend.OwnerUserID
|
||||
friendPb.Remark = friend.Remark
|
||||
friendPb.AddSource = friend.AddSource
|
||||
friendPb.OperatorUserID = friend.OperatorUserID
|
||||
friendPb.Ex = friend.Ex
|
||||
friendPb.IsPinned = friend.IsPinned
|
||||
|
||||
friendPb.FriendUser.UserID = users[friend.FriendUserID].UserID
|
||||
friendPb.FriendUser.Nickname = users[friend.FriendUserID].Nickname
|
||||
|
||||
@ -127,13 +127,10 @@ func (c *conversationDatabase) SetUsersConversationFieldTx(ctx context.Context,
|
||||
var conversations []*relationtb.Conversation
|
||||
now := time.Now()
|
||||
for _, v := range NotUserIDs {
|
||||
temp := new(relationtb.Conversation)
|
||||
if err = datautil.CopyStructFields(temp, conversation); err != nil {
|
||||
return err
|
||||
}
|
||||
temp := *conversation
|
||||
temp.OwnerUserID = v
|
||||
temp.CreateTime = now
|
||||
conversations = append(conversations, temp)
|
||||
conversations = append(conversations, &temp)
|
||||
}
|
||||
if len(conversations) > 0 {
|
||||
err = c.conversationDB.Create(ctx, conversations)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user