|
|
|
|
@ -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
|
|
|
|
|
|