diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index 0e2bfe4dafee7244d31f17d0fb4082ca929be4f5..81e124476393549f8ff88154d8b8cd6fe8791fed 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -44,6 +44,7 @@ const ( GroupMsg = 201 //SysRelated + NotificationBegin = 1000 FriendApplicationApprovedNotification = 1201 //add_friend_response FriendApplicationRejectedNotification = 1202 //add_friend_response @@ -66,6 +67,7 @@ const ( MemberKickedNotification = 1508 MemberInvitedNotification = 1509 MemberEnterNotification = 1510 + NotificationEnd = 2000 //MsgFrom UserMsgType = 100 diff --git a/pkg/common/db/model_struct.go b/pkg/common/db/model_struct.go index 0e36add1fbed8f08e63bddb17a829f11e287a037..25e3bf0cdc75261fd19e094f95e9b082e3daadb8 100644 --- a/pkg/common/db/model_struct.go +++ b/pkg/common/db/model_struct.go @@ -181,7 +181,7 @@ type ChatLog struct { 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 []byte `gorm:"column:content;type:varchar(1000)" json:"content"` + 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"` diff --git a/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go b/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go index cea33b1a268e855d659a886a806f5ccb6d4c6f6e..fef4c1fb26d0f2455481e8281a18c052b3ea6b93 100644 --- a/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go +++ b/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go @@ -10,7 +10,10 @@ import ( "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db" pbMsg "Open_IM/pkg/proto/chat" + "Open_IM/pkg/proto/sdk_ws" "Open_IM/pkg/utils" + "github.com/golang/protobuf/jsonpb" + "github.com/golang/protobuf/proto" "github.com/jinzhu/copier" ) @@ -27,7 +30,19 @@ func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error { case constant.SingleChatType: chatLog.RecvID = msg.MsgData.RecvID } - chatLog.Content = msg.MsgData.Content + if msg.MsgData.ContentType >= constant.NotificationBegin && msg.MsgData.ContentType <= constant.NotificationEnd { + var tips server_api_params.TipsComm + _ = proto.Unmarshal(msg.MsgData.Content, &tips) + marshaler := jsonpb.Marshaler{ + OrigName: true, + EnumsAsInts: false, + EmitDefaults: false, + } + chatLog.Content, _ = marshaler.MarshalToString(&tips) + + } else { + chatLog.Content = string(msg.MsgData.Content) + } chatLog.CreateTime = utils.UnixMillSecondToTime(msg.MsgData.CreateTime) chatLog.SendTime = utils.UnixMillSecondToTime(msg.MsgData.SendTime) return dbConn.Table("chat_logs").Create(chatLog).Error