videoplayer/dao/im.go

57 lines
1.5 KiB
Go
Raw Normal View History

2024-08-02 09:47:33 +08:00
package dao
import "gorm.io/gorm"
type Message struct {
gorm.Model
FromUserID int `gorm:"column:from_user_id"`
ToUserID int `gorm:"column:to_user_id"`
GroupID int `gorm:"column:group_id"`
Msg string `gorm:"column:msg"`
Status int `gorm:"column:status"` //单聊时才有0,已读2未读
Type int `gorm:"column:type"` //1为单聊2为群聊3为系统消息
}
type Group struct {
gorm.Model
GroupName string `gorm:"column:group_name"`
}
type GroupUser struct {
gorm.Model
GroupID int `gorm:"column:group_id"`
UserID int `gorm:"column:user_id"`
IsMaster int `gorm:"column:is_master"`
}
type Friend struct {
gorm.Model
UserID int `gorm:"column:user_id"`
FriendID int `gorm:"column:friend_id"`
}
// 创建单聊消息
func CreateSimpleMessage(from_user_id, to_user_id int, message string) error {
msg := Message{FromUserID: from_user_id, ToUserID: to_user_id, Msg: message, Type: 1, Status: 0}
res := DB.Debug().Create(msg)
return res.Error
}
// 每20个消息一组请求index*20
func GetMsgUserByIndex(from_user_id, to_user_id, index int) ([]Message, error) {
var msgs []Message
res := DB.Debug().Where("from_user_id = ? and to_user_id = ?", from_user_id, to_user_id).Find(&msgs).Order("order by createAt DESC").Limit(20 * index)
return msgs, res.Error
}
// 修改信息
func UpdateMessage() {
}
func FindMessageByID(id uint) []Message {
var msgs []Message
DB.Debug().Where("id = ?", id).Find(msgs)
return msgs
}