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
|
// Deprecated
|
||||||
func (c *conversationServer) SetConversation(ctx context.Context, req *pbconversation.SetConversationReq) (*pbconversation.SetConversationResp, error) {
|
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
|
var conversation dbModel.Conversation
|
||||||
if err := datautil.CopyStructFields(&conversation, req.Conversation); err != nil {
|
conversation.OwnerUserID = req.Conversation.OwnerUserID
|
||||||
return nil, err
|
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})
|
err := c.conversationDatabase.SetUserConversations(ctx, req.Conversation.OwnerUserID, []*dbModel.Conversation{&conversation})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -606,9 +625,17 @@ func (c *conversationServer) getConversationInfo(
|
|||||||
}
|
}
|
||||||
for conversationID, chatLog := range chatLogs {
|
for conversationID, chatLog := range chatLogs {
|
||||||
pbchatLog := &pbconversation.ConversationElem{}
|
pbchatLog := &pbconversation.ConversationElem{}
|
||||||
msgInfo := &pbconversation.MsgInfo{}
|
msgInfo := &pbconversation.MsgInfo{
|
||||||
if err := datautil.CopyStructFields(msgInfo, chatLog); err != nil {
|
ServerMsgID: chatLog.ServerMsgID,
|
||||||
return nil, err
|
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 {
|
switch chatLog.SessionType {
|
||||||
case constant.SingleChatType:
|
case constant.SingleChatType:
|
||||||
|
|||||||
@ -24,7 +24,6 @@ import (
|
|||||||
"github.com/openimsdk/protocol/msg"
|
"github.com/openimsdk/protocol/msg"
|
||||||
"github.com/openimsdk/protocol/sdkws"
|
"github.com/openimsdk/protocol/sdkws"
|
||||||
"github.com/openimsdk/tools/log"
|
"github.com/openimsdk/tools/log"
|
||||||
"github.com/openimsdk/tools/utils/datautil"
|
|
||||||
"github.com/openimsdk/tools/utils/timeutil"
|
"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
|
// Construct response with updated information
|
||||||
for _, chatLog := range chatLogs {
|
for _, chatLog := range chatLogs {
|
||||||
pbchatLog := &msg.ChatLog{}
|
pbchatLog := &msg.ChatLog{}
|
||||||
datautil.CopyStructFields(pbchatLog, chatLog.MsgData)
|
msgData := chatLog.MsgData
|
||||||
pbchatLog.SendTime = chatLog.MsgData.SendTime
|
pbchatLog.ServerMsgID = msgData.ServerMsgID
|
||||||
pbchatLog.CreateTime = chatLog.MsgData.CreateTime
|
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 == "" {
|
if chatLog.MsgData.SenderNickname == "" {
|
||||||
pbchatLog.SenderNickname = sendMap[chatLog.MsgData.SendID]
|
pbchatLog.SenderNickname = sendMap[chatLog.MsgData.SendID]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,46 +15,120 @@
|
|||||||
package convert
|
package convert
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
||||||
"github.com/openimsdk/protocol/conversation"
|
"github.com/openimsdk/protocol/conversation"
|
||||||
"github.com/openimsdk/tools/utils/datautil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ConversationDB2Pb(conversationDB *model.Conversation) *conversation.Conversation {
|
func ConversationDB2Pb(conversationDB *model.Conversation) *conversation.Conversation {
|
||||||
conversationPB := &conversation.Conversation{}
|
if conversationDB == nil {
|
||||||
conversationPB.LatestMsgDestructTime = conversationDB.LatestMsgDestructTime.UnixMilli()
|
|
||||||
if err := datautil.CopyStructFields(conversationPB, conversationDB); err != nil {
|
|
||||||
return 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) {
|
func ConversationsDB2Pb(conversationsDB []*model.Conversation) (conversationsPB []*conversation.Conversation) {
|
||||||
for _, conversationDB := range conversationsDB {
|
for _, conversationDB := range conversationsDB {
|
||||||
conversationPB := &conversation.Conversation{}
|
if conversationDB == nil {
|
||||||
if err := datautil.CopyStructFields(conversationPB, conversationDB); err != nil {
|
|
||||||
continue
|
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)
|
conversationsPB = append(conversationsPB, conversationPB)
|
||||||
}
|
}
|
||||||
return conversationsPB
|
return conversationsPB
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConversationPb2DB(conversationPB *conversation.Conversation) *model.Conversation {
|
func ConversationPb2DB(conversationPB *conversation.Conversation) *model.Conversation {
|
||||||
conversationDB := &model.Conversation{}
|
if conversationPB == nil {
|
||||||
if err := datautil.CopyStructFields(conversationDB, conversationPB); err != nil {
|
|
||||||
return 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
|
return conversationDB
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConversationsPb2DB(conversationsPB []*conversation.Conversation) (conversationsDB []*model.Conversation) {
|
func ConversationsPb2DB(conversationsPB []*conversation.Conversation) (conversationsDB []*model.Conversation) {
|
||||||
for _, conversationPB := range conversationsPB {
|
for _, conversationPB := range conversationsPB {
|
||||||
conversationDB := &model.Conversation{}
|
if conversationPB == nil {
|
||||||
if err := datautil.CopyStructFields(conversationDB, conversationPB); err != nil {
|
|
||||||
continue
|
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)
|
conversationsDB = append(conversationsDB, conversationDB)
|
||||||
}
|
}
|
||||||
return conversationsDB
|
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/common/storage/model"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/notification/common_user"
|
"github.com/openimsdk/open-im-server/v3/pkg/notification/common_user"
|
||||||
"github.com/openimsdk/protocol/relation"
|
"github.com/openimsdk/protocol/relation"
|
||||||
|
|
||||||
"github.com/openimsdk/protocol/sdkws"
|
"github.com/openimsdk/protocol/sdkws"
|
||||||
"github.com/openimsdk/tools/utils/datautil"
|
"github.com/openimsdk/tools/utils/datautil"
|
||||||
"github.com/openimsdk/tools/utils/timeutil"
|
"github.com/openimsdk/tools/utils/timeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func FriendPb2DB(friend *sdkws.FriendInfo) *model.Friend {
|
func FriendPb2DB(friend *sdkws.FriendInfo) *model.Friend {
|
||||||
dbFriend := &model.Friend{}
|
if friend == nil {
|
||||||
err := datautil.CopyStructFields(dbFriend, friend)
|
|
||||||
if err != nil {
|
|
||||||
return 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.FriendUserID = friend.FriendUser.UserID
|
||||||
dbFriend.CreateTime = timeutil.UnixSecondToTime(friend.CreateTime)
|
dbFriend.CreateTime = timeutil.UnixSecondToTime(friend.CreateTime)
|
||||||
return dbFriend
|
return dbFriend
|
||||||
@ -69,10 +73,12 @@ func FriendsDB2Pb(ctx context.Context, friendsDB []*model.Friend, getUsers func(
|
|||||||
}
|
}
|
||||||
for _, friend := range friendsDB {
|
for _, friend := range friendsDB {
|
||||||
friendPb := &sdkws.FriendInfo{FriendUser: &sdkws.UserInfo{}}
|
friendPb := &sdkws.FriendInfo{FriendUser: &sdkws.UserInfo{}}
|
||||||
err := datautil.CopyStructFields(friendPb, friend)
|
friendPb.OwnerUserID = friend.OwnerUserID
|
||||||
if err != nil {
|
friendPb.Remark = friend.Remark
|
||||||
return nil, err
|
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.UserID = users[friend.FriendUserID].UserID
|
||||||
friendPb.FriendUser.Nickname = users[friend.FriendUserID].Nickname
|
friendPb.FriendUser.Nickname = users[friend.FriendUserID].Nickname
|
||||||
|
|||||||
@ -127,13 +127,10 @@ func (c *conversationDatabase) SetUsersConversationFieldTx(ctx context.Context,
|
|||||||
var conversations []*relationtb.Conversation
|
var conversations []*relationtb.Conversation
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
for _, v := range NotUserIDs {
|
for _, v := range NotUserIDs {
|
||||||
temp := new(relationtb.Conversation)
|
temp := *conversation
|
||||||
if err = datautil.CopyStructFields(temp, conversation); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
temp.OwnerUserID = v
|
temp.OwnerUserID = v
|
||||||
temp.CreateTime = now
|
temp.CreateTime = now
|
||||||
conversations = append(conversations, temp)
|
conversations = append(conversations, &temp)
|
||||||
}
|
}
|
||||||
if len(conversations) > 0 {
|
if len(conversations) > 0 {
|
||||||
err = c.conversationDB.Create(ctx, conversations)
|
err = c.conversationDB.Create(ctx, conversations)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user