diff options
Diffstat (limited to 'internal/db/bundb/emoji.go')
-rw-r--r-- | internal/db/bundb/emoji.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/internal/db/bundb/emoji.go b/internal/db/bundb/emoji.go index 4fb4f0ce6..51d767a7b 100644 --- a/internal/db/bundb/emoji.go +++ b/internal/db/bundb/emoji.go @@ -68,6 +68,43 @@ func (e *emojiDB) UpdateEmoji(ctx context.Context, emoji *gtsmodel.Emoji, column return emoji, nil } +func (e *emojiDB) DeleteEmojiByID(ctx context.Context, id string) db.Error { + if err := e.conn.RunInTx(ctx, func(tx bun.Tx) error { + // delete links between this emoji and any statuses that use it + if _, err := tx. + NewDelete(). + TableExpr("? AS ?", bun.Ident("status_to_emojis"), bun.Ident("status_to_emoji")). + Where("? = ?", bun.Ident("status_to_emoji.emoji_id"), id). + Exec(ctx); err != nil { + return err + } + + // delete links between this emoji and any accounts that use it + if _, err := tx. + NewDelete(). + TableExpr("? AS ?", bun.Ident("account_to_emojis"), bun.Ident("account_to_emoji")). + Where("? = ?", bun.Ident("account_to_emoji.emoji_id"), id). + Exec(ctx); err != nil { + return err + } + + if _, err := tx. + NewDelete(). + TableExpr("? AS ?", bun.Ident("emojis"), bun.Ident("emoji")). + Where("? = ?", bun.Ident("emoji.id"), id). + Exec(ctx); err != nil { + return e.conn.ProcessError(err) + } + + return nil + }); err != nil { + return err + } + + e.cache.Invalidate(id) + return nil +} + func (e *emojiDB) GetEmojis(ctx context.Context, domain string, includeDisabled bool, includeEnabled bool, shortcode string, maxShortcodeDomain string, minShortcodeDomain string, limit int) ([]*gtsmodel.Emoji, db.Error) { emojiIDs := []string{} |