You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.3 KiB

4 years ago
package models
4 years ago
import (
"time"
"github.com/imdotdev/im.dev/server/pkg/db"
)
4 years ago
type Comment struct {
ID string `json:"id"`
TargetID string `json:"targetID"` // 被评论的文章、书籍等ID
4 years ago
CreatorID string `json:"creatorID"`
4 years ago
Creator *UserSimple `json:"creator"`
Md string `json:"md"`
Likes int `json:"likes"`
Liked bool `json:"liked"`
Replies []*Comment `json:"replies"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
}
type Comments []*Comment
func (ar Comments) Len() int { return len(ar) }
func (ar Comments) Swap(i, j int) { ar[i], ar[j] = ar[j], ar[i] }
func (ar Comments) Less(i, j int) bool {
return ar[i].Created.Unix() > ar[j].Created.Unix()
}
type FavorComments []*Comment
func (ar FavorComments) Len() int { return len(ar) }
func (ar FavorComments) Swap(i, j int) { ar[i], ar[j] = ar[j], ar[i] }
func (ar FavorComments) Less(i, j int) bool {
return ar[i].Likes > ar[j].Likes
}
4 years ago
func GetCommentStoryID(id string) string {
var t string
db.Conn.QueryRow("SELECT story_id FROM comments WHERE id=?", id).Scan(&t)
if GetIDType(t) != IDTypeComment {
return t
}
var t1 string
db.Conn.QueryRow("SELECT story_id FROM comments WHERE id=?", t).Scan(&t1)
return t1
}