Prep for reactions, some fixes and improvements
Some checks failed
/ docker (push) Failing after 1m35s
Some checks failed
/ docker (push) Failing after 1m35s
This commit is contained in:
parent
4b62c32247
commit
8947d97825
13 changed files with 262 additions and 43 deletions
|
@ -27,7 +27,7 @@ func newEmote(db *gorm.DB, opts ...gen.DOOption) emote {
|
|||
|
||||
tableName := _emote.emoteDo.TableName()
|
||||
_emote.ALL = field.NewAsterisk(tableName)
|
||||
_emote.ID = field.NewUint(tableName, "id")
|
||||
_emote.ID = field.NewString(tableName, "id")
|
||||
_emote.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_emote.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_emote.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
@ -73,7 +73,7 @@ type emote struct {
|
|||
emoteDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Uint
|
||||
ID field.String
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
|
@ -99,7 +99,7 @@ func (e emote) As(alias string) *emote {
|
|||
|
||||
func (e *emote) updateTableName(table string) *emote {
|
||||
e.ALL = field.NewAsterisk(table)
|
||||
e.ID = field.NewUint(table, "id")
|
||||
e.ID = field.NewString(table, "id")
|
||||
e.CreatedAt = field.NewTime(table, "created_at")
|
||||
e.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
e.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
|
|
@ -30,6 +30,8 @@ func newNoteToFeed(db *gorm.DB, opts ...gen.DOOption) noteToFeed {
|
|||
_noteToFeed.ID = field.NewUint64(tableName, "id")
|
||||
_noteToFeed.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_noteToFeed.NoteId = field.NewString(tableName, "note_id")
|
||||
_noteToFeed.FeedId = field.NewUint64(tableName, "feed_id")
|
||||
_noteToFeed.Reason = field.NewString(tableName, "reason")
|
||||
_noteToFeed.Note = noteToFeedBelongsToNote{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
|
@ -399,6 +401,17 @@ func newNoteToFeed(db *gorm.DB, opts ...gen.DOOption) noteToFeed {
|
|||
},
|
||||
}
|
||||
|
||||
_noteToFeed.Feed = noteToFeedBelongsToFeed{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Feed", "models.Feed"),
|
||||
Owner: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Feed.Owner", "models.User"),
|
||||
},
|
||||
}
|
||||
|
||||
_noteToFeed.fillFieldMap()
|
||||
|
||||
return _noteToFeed
|
||||
|
@ -411,8 +424,12 @@ type noteToFeed struct {
|
|||
ID field.Uint64
|
||||
CreatedAt field.Time
|
||||
NoteId field.String
|
||||
FeedId field.Uint64
|
||||
Reason field.String
|
||||
Note noteToFeedBelongsToNote
|
||||
|
||||
Feed noteToFeedBelongsToFeed
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
|
@ -431,6 +448,8 @@ func (n *noteToFeed) updateTableName(table string) *noteToFeed {
|
|||
n.ID = field.NewUint64(table, "id")
|
||||
n.CreatedAt = field.NewTime(table, "created_at")
|
||||
n.NoteId = field.NewString(table, "note_id")
|
||||
n.FeedId = field.NewUint64(table, "feed_id")
|
||||
n.Reason = field.NewString(table, "reason")
|
||||
|
||||
n.fillFieldMap()
|
||||
|
||||
|
@ -447,10 +466,12 @@ func (n *noteToFeed) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|||
}
|
||||
|
||||
func (n *noteToFeed) fillFieldMap() {
|
||||
n.fieldMap = make(map[string]field.Expr, 4)
|
||||
n.fieldMap = make(map[string]field.Expr, 7)
|
||||
n.fieldMap["id"] = n.ID
|
||||
n.fieldMap["created_at"] = n.CreatedAt
|
||||
n.fieldMap["note_id"] = n.NoteId
|
||||
n.fieldMap["feed_id"] = n.FeedId
|
||||
n.fieldMap["reason"] = n.Reason
|
||||
|
||||
}
|
||||
|
||||
|
@ -458,12 +479,15 @@ func (n noteToFeed) clone(db *gorm.DB) noteToFeed {
|
|||
n.noteToFeedDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
n.Note.db = db.Session(&gorm.Session{Initialized: true})
|
||||
n.Note.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
n.Feed.db = db.Session(&gorm.Session{Initialized: true})
|
||||
n.Feed.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
return n
|
||||
}
|
||||
|
||||
func (n noteToFeed) replaceDB(db *gorm.DB) noteToFeed {
|
||||
n.noteToFeedDo.ReplaceDB(db)
|
||||
n.Note.db = db.Session(&gorm.Session{})
|
||||
n.Feed.db = db.Session(&gorm.Session{})
|
||||
return n
|
||||
}
|
||||
|
||||
|
@ -675,6 +699,91 @@ func (a noteToFeedBelongsToNoteTx) Unscoped() *noteToFeedBelongsToNoteTx {
|
|||
return &a
|
||||
}
|
||||
|
||||
type noteToFeedBelongsToFeed struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
|
||||
Owner struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeed) Where(conds ...field.Expr) *noteToFeedBelongsToFeed {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeed) WithContext(ctx context.Context) *noteToFeedBelongsToFeed {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeed) Session(session *gorm.Session) *noteToFeedBelongsToFeed {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeed) Model(m *models.NoteToFeed) *noteToFeedBelongsToFeedTx {
|
||||
return ¬eToFeedBelongsToFeedTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeed) Unscoped() *noteToFeedBelongsToFeed {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type noteToFeedBelongsToFeedTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a noteToFeedBelongsToFeedTx) Find() (result *models.Feed, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeedTx) Append(values ...*models.Feed) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeedTx) Replace(values ...*models.Feed) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeedTx) Delete(values ...*models.Feed) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeedTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeedTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a noteToFeedBelongsToFeedTx) Unscoped() *noteToFeedBelongsToFeedTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type noteToFeedDo struct{ gen.DO }
|
||||
|
||||
type INoteToFeedDo interface {
|
||||
|
|
|
@ -27,13 +27,14 @@ func newReaction(db *gorm.DB, opts ...gen.DOOption) reaction {
|
|||
|
||||
tableName := _reaction.reactionDo.TableName()
|
||||
_reaction.ALL = field.NewAsterisk(tableName)
|
||||
_reaction.ID = field.NewUint(tableName, "id")
|
||||
_reaction.ID = field.NewString(tableName, "id")
|
||||
_reaction.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_reaction.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_reaction.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_reaction.NoteId = field.NewString(tableName, "note_id")
|
||||
_reaction.ReactorId = field.NewString(tableName, "reactor_id")
|
||||
_reaction.EmoteId = field.NewField(tableName, "emote_id")
|
||||
_reaction.Content = field.NewField(tableName, "content")
|
||||
_reaction.Note = reactionBelongsToNote{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
|
@ -424,13 +425,14 @@ type reaction struct {
|
|||
reactionDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Uint
|
||||
ID field.String
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
NoteId field.String
|
||||
ReactorId field.String
|
||||
EmoteId field.Field
|
||||
Content field.Field
|
||||
Note reactionBelongsToNote
|
||||
|
||||
Reactor reactionBelongsToReactor
|
||||
|
@ -452,13 +454,14 @@ func (r reaction) As(alias string) *reaction {
|
|||
|
||||
func (r *reaction) updateTableName(table string) *reaction {
|
||||
r.ALL = field.NewAsterisk(table)
|
||||
r.ID = field.NewUint(table, "id")
|
||||
r.ID = field.NewString(table, "id")
|
||||
r.CreatedAt = field.NewTime(table, "created_at")
|
||||
r.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
r.DeletedAt = field.NewField(table, "deleted_at")
|
||||
r.NoteId = field.NewString(table, "note_id")
|
||||
r.ReactorId = field.NewString(table, "reactor_id")
|
||||
r.EmoteId = field.NewField(table, "emote_id")
|
||||
r.Content = field.NewField(table, "content")
|
||||
|
||||
r.fillFieldMap()
|
||||
|
||||
|
@ -475,7 +478,7 @@ func (r *reaction) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|||
}
|
||||
|
||||
func (r *reaction) fillFieldMap() {
|
||||
r.fieldMap = make(map[string]field.Expr, 10)
|
||||
r.fieldMap = make(map[string]field.Expr, 11)
|
||||
r.fieldMap["id"] = r.ID
|
||||
r.fieldMap["created_at"] = r.CreatedAt
|
||||
r.fieldMap["updated_at"] = r.UpdatedAt
|
||||
|
@ -483,6 +486,7 @@ func (r *reaction) fillFieldMap() {
|
|||
r.fieldMap["note_id"] = r.NoteId
|
||||
r.fieldMap["reactor_id"] = r.ReactorId
|
||||
r.fieldMap["emote_id"] = r.EmoteId
|
||||
r.fieldMap["content"] = r.Content
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,21 @@
|
|||
package models
|
||||
|
||||
import "gorm.io/gorm"
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Emotes are combinations of a name, the server it originated from
|
||||
// and the media for it
|
||||
// and the media for it. Only represents custom emotes, not characters found in unicode
|
||||
//
|
||||
// TODO: Include the case of unicode icons being used as emote
|
||||
type Emote struct {
|
||||
gorm.Model // Standard gorm model for id and timestamps
|
||||
Metadata MediaMetadata // The media used by this emote
|
||||
MetadataId string // Id of the media information, primarily for gorm
|
||||
ID string `gorm:"primarykey"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||
Metadata MediaMetadata // The media used by this emote
|
||||
MetadataId string // Id of the media information, primarily for gorm
|
||||
// Name of the emote. Also the text for using it in a message (ex. :bob:)
|
||||
Name string
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package models
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
@ -10,12 +11,15 @@ import (
|
|||
// A reaction may contain some content text. If yes, this is the reaction.
|
||||
// It also may contain a specifically linked emote (via tag). If yes, this is the reaction and takes precedence over the content
|
||||
type Reaction struct {
|
||||
gorm.Model
|
||||
ID string `gorm:"primarykey"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||
Note Note
|
||||
NoteId string
|
||||
Reactor User
|
||||
ReactorId string
|
||||
Emote *Emote // Emote is optional. If not set, use the default emote of the server
|
||||
EmoteId sql.NullInt64
|
||||
EmoteId sql.NullString
|
||||
Content sql.NullString // Content/text of the reaction. Used for example in cases where a unicode character is sent as emote reaction
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue