feat: support async message sending now (close #58)

This commit is contained in:
JustSong
2023-05-07 12:58:47 +08:00
parent 1cade7a218
commit 96e08578ec
6 changed files with 120 additions and 19 deletions
+21 -6
View File
@@ -18,14 +18,15 @@ type Message struct {
HTMLContent string `json:"html_content" gorm:"-:all"`
Timestamp int64 `json:"timestamp" gorm:"type:bigint"`
Link string `json:"link" gorm:"unique;index"`
To string `json:"to" gorm:"column:to"` // if specified, will send to this user(s)
Status int `json:"status" gorm:"default:0"` // pending, sent, failed
OpenId string `json:"openid" gorm:"-:all"` // alias for to
Desp string `json:"desp" gorm:"-:all"` // alias for content
Short string `json:"short" gorm:"-:all"` // alias for description
To string `json:"to" gorm:"column:to"` // if specified, will send to this user(s)
Status int `json:"status" gorm:"default:0;index"` // pending, sent, failed
OpenId string `json:"openid" gorm:"-:all"` // alias for to
Desp string `json:"desp" gorm:"-:all"` // alias for content
Short string `json:"short" gorm:"-:all"` // alias for description
Async bool `json:"async" gorm:"-"` // if true, will send message asynchronously
}
func GetMessageById(id int, userId int) (*Message, error) {
func GetMessageByIds(id int, userId int) (*Message, error) {
if id == 0 || userId == 0 {
return nil, errors.New("id 或 userId 为空!")
}
@@ -34,6 +35,20 @@ func GetMessageById(id int, userId int) (*Message, error) {
return &message, err
}
func GetMessageById(id int) (*Message, error) {
if id == 0 {
return nil, errors.New("id 为空!")
}
message := Message{Id: id}
err := DB.Where(message).First(&message).Error
return &message, err
}
func GetAsyncPendingMessageIds() (ids []int, err error) {
err = DB.Model(&Message{}).Where("status = ?", common.MessageSendStatusAsyncPending).Pluck("id", &ids).Error
return ids, err
}
func GetMessageByLink(link string) (*Message, error) {
if link == "" {
return nil, errors.New("link 为空!")