reprogl
1package models2
3import (4"database/sql"5"time"6
7"xelbot.com/reprogl/container"8"xelbot.com/reprogl/utils/hashid"9)
10
11type Commentator struct {12Name string13Website sql.NullString14Email sql.NullString15CommentatorID sql.NullInt3216AuthorID sql.NullInt3217CommentsCount int18Gender int19RottenLink bool20AvatarVariant int21}
22
23type Comment struct {24ID int25Text string26Depth int27CreatedAt time.Time28Deleted bool29Commentator
30
31IP sql.NullString32CountryCode string33UserAgent sql.NullString34}
35
36type CommentatorForGravatar struct {37ID int38Email sql.NullString39FakeEmail sql.NullBool40}
41
42type CommentList []*Comment43
44type CommentatorList []*Commentator45
46func (c *Comment) Avatar() (src string) {47if c.Deleted {48src = container.GetConfig().CDNBaseURL + "/images/avatar/clown.png"49
50return51}52
53return c.Commentator.Avatar()54}
55
56func (ctt *Commentator) Avatar() string {57var id int58var options hashid.Option59
60switch {61case ctt.CommentatorID.Valid:62id = int(ctt.CommentatorID.Int32)63options = hashid.Commentator64case ctt.AuthorID.Valid:65id = int(ctt.AuthorID.Int32)66options = hashid.User67}68
69if ctt.Gender == 1 {70options |= hashid.Male71} else {72options |= hashid.Female73}74
75if ctt.AvatarVariant > 0 {76options += hashid.Option(ctt.AvatarVariant << 4)77}78
79return AvatarLink(id, options)80}
81
82func (c *CommentatorForGravatar) NeedToCheckGravatar() bool {83return c.Email.Valid && c.FakeEmail.Valid && !c.FakeEmail.Bool84}
85
86func (c *CommentatorForGravatar) GetEmail() string {87return c.Email.String88}
89