mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-24 10:22:36 +08:00
chat log model update
This commit is contained in:
parent
3c64d84980
commit
911100923f
@ -165,3 +165,22 @@ type Black struct {
|
|||||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||||
Ex string `gorm:"column:ex;size:1024"`
|
Ex string `gorm:"column:ex;size:1024"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ChatLog struct {
|
||||||
|
ServerMsgID string `gorm:"column:server_msg_id;primary_key;type:char(64)" json:"serverMsgID"`
|
||||||
|
ClientMsgID string `gorm:"column:client_msg_id;type:char(64)" json:"clientMsgID"`
|
||||||
|
SendID string `gorm:"column:send_id;type:char(64)" json:"sendID"`
|
||||||
|
RecvID string `gorm:"column:recv_id;type:char(64)" json:"recvID"`
|
||||||
|
SenderPlatformID int32 `gorm:"column:sender_platform_id" json:"senderPlatformID"`
|
||||||
|
SenderNickname string `gorm:"column:sender_nick_name;type:varchar(255)" json:"senderNickname"`
|
||||||
|
SenderFaceURL string `gorm:"column:sender_face_url;type:varchar(255)" json:"senderFaceURL"`
|
||||||
|
SessionType int32 `gorm:"column:session_type" json:"sessionType"`
|
||||||
|
MsgFrom int32 `gorm:"column:msg_from" json:"msgFrom"`
|
||||||
|
ContentType int32 `gorm:"column:content_type" json:"contentType"`
|
||||||
|
Content string `gorm:"column:content;type:varchar(1000)" json:"content"`
|
||||||
|
Status int32 `gorm:"column:status" json:"status"`
|
||||||
|
Seq uint32 `gorm:"column:seq;index:index_seq;default:0" json:"seq"`
|
||||||
|
SendTime time.Time `gorm:"column:send_time" json:"sendTime"`
|
||||||
|
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
|
||||||
|
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
|
||||||
|
}
|
||||||
|
@ -58,7 +58,7 @@ func initMysqlDB() {
|
|||||||
&GroupMember{},
|
&GroupMember{},
|
||||||
&GroupRequest{},
|
&GroupRequest{},
|
||||||
&User{},
|
&User{},
|
||||||
&Black{})
|
&Black{}, &ChatLog{})
|
||||||
db.Set("gorm:table_options", "CHARSET=utf8")
|
db.Set("gorm:table_options", "CHARSET=utf8")
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -11,45 +11,24 @@ import (
|
|||||||
"Open_IM/pkg/common/db"
|
"Open_IM/pkg/common/db"
|
||||||
pbMsg "Open_IM/pkg/proto/chat"
|
pbMsg "Open_IM/pkg/proto/chat"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"database/sql"
|
"github.com/jinzhu/copier"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ChatLog Chat information table structure
|
|
||||||
type ChatLog struct {
|
|
||||||
MsgId string `gorm:"primary_key"` // Chat history primary key ID
|
|
||||||
SendID string `gorm:"column:send_id"` // Send ID
|
|
||||||
RecvID string `gorm:"column:recv_id"` //Receive ID
|
|
||||||
SendTime time.Time `gorm:"column:send_time"` // Send time
|
|
||||||
SessionType int32 `gorm:"column:session_type"` // Session type
|
|
||||||
ContentType int32 `gorm:"column:content_type"` // Message content type
|
|
||||||
MsgFrom int32 `gorm:"column:msg_from"` // Source, user, system
|
|
||||||
Content string `gorm:"column:content"` // Chat content
|
|
||||||
SenderPlatformID int32 `gorm:"column:sender_platform_id"` //The sender's platform ID
|
|
||||||
Remark sql.NullString `gorm:"column:remark"` // remark
|
|
||||||
}
|
|
||||||
|
|
||||||
func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error {
|
func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error {
|
||||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
chatLog := ChatLog{
|
chatLog := new(db.ChatLog)
|
||||||
MsgId: msg.MsgData.ServerMsgID,
|
copier.Copy(chatLog, msg.MsgData)
|
||||||
SendID: msg.MsgData.SendID,
|
|
||||||
SendTime: utils.UnixNanoSecondToTime(msg.MsgData.SendTime),
|
|
||||||
SessionType: msg.MsgData.SessionType,
|
|
||||||
ContentType: msg.MsgData.ContentType,
|
|
||||||
MsgFrom: msg.MsgData.MsgFrom,
|
|
||||||
Content: string(msg.MsgData.Content),
|
|
||||||
SenderPlatformID: msg.MsgData.SenderPlatformID,
|
|
||||||
}
|
|
||||||
switch msg.MsgData.SessionType {
|
switch msg.MsgData.SessionType {
|
||||||
case constant.GroupChatType:
|
case constant.GroupChatType:
|
||||||
chatLog.RecvID = msg.MsgData.GroupID
|
chatLog.RecvID = msg.MsgData.GroupID
|
||||||
case constant.SingleChatType:
|
case constant.SingleChatType:
|
||||||
chatLog.RecvID = msg.MsgData.RecvID
|
chatLog.RecvID = msg.MsgData.RecvID
|
||||||
}
|
}
|
||||||
|
chatLog.Content = string(msg.MsgData.Content)
|
||||||
|
chatLog.CreateTime = utils.UnixNanoSecondToTime(msg.MsgData.CreateTime)
|
||||||
|
chatLog.SendTime = utils.UnixNanoSecondToTime(msg.MsgData.SendTime)
|
||||||
return dbConn.Table("chat_log").Create(chatLog).Error
|
return dbConn.Table("chat_log").Create(chatLog).Error
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user