diff options
Diffstat (limited to 'internal/db/bundb/emoji.go')
| -rw-r--r-- | internal/db/bundb/emoji.go | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/internal/db/bundb/emoji.go b/internal/db/bundb/emoji.go index 31092d0d2..d1cb9dfbd 100644 --- a/internal/db/bundb/emoji.go +++ b/internal/db/bundb/emoji.go @@ -132,28 +132,32 @@ func (e *emojiDB) DeleteEmojiByID(ctx context.Context, id string) error { } for _, statusID := range statusIDs { - var emojiIDs []string + status := new(gtsmodel.Status) - // Select statuses with ID. - if _, err := tx.NewSelect(). - Table("statuses"). + // Select status emoji IDs. + if err := tx.NewSelect(). + Model(status). Column("emojis"). Where("? = ?", bun.Ident("id"), statusID). - Exec(ctx); err != nil && + Scan(ctx); err != nil && err != sql.ErrNoRows { return err } - // Delete all instances of this emoji ID from status emojis. - emojiIDs = slices.DeleteFunc(emojiIDs, func(emojiID string) bool { - return emojiID == id - }) + // Delete all instances of this + // emoji ID from status emoji IDs. + status.EmojiIDs = slices.DeleteFunc( + status.EmojiIDs, + func(emojiID string) bool { + return emojiID == id + }, + ) // Update status emoji IDs. if _, err := tx.NewUpdate(). - Table("statuses"). + Model(status). Where("? = ?", bun.Ident("id"), statusID). - Set("emojis = ?", emojiIDs). + Column("emojis"). Exec(ctx); err != nil && err != sql.ErrNoRows { return err @@ -161,35 +165,39 @@ func (e *emojiDB) DeleteEmojiByID(ctx context.Context, id string) error { } for _, accountID := range accountIDs { - var emojiIDs []string + account := new(gtsmodel.Account) - // Select account with ID. - if _, err := tx.NewSelect(). - Table("accounts"). + // Select account emoji IDs. + if err := tx.NewSelect(). + Model(account). Column("emojis"). Where("? = ?", bun.Ident("id"), accountID). - Exec(ctx); err != nil && + Scan(ctx); err != nil && err != sql.ErrNoRows { return err } - // Delete all instances of this emoji ID from account emojis. - emojiIDs = slices.DeleteFunc(emojiIDs, func(emojiID string) bool { - return emojiID == id - }) + // Delete all instances of this + // emoji ID from account emoji IDs. + account.EmojiIDs = slices.DeleteFunc( + account.EmojiIDs, + func(emojiID string) bool { + return emojiID == id + }, + ) // Update account emoji IDs. if _, err := tx.NewUpdate(). - Table("accounts"). + Model(account). Where("? = ?", bun.Ident("id"), accountID). - Set("emojis = ?", emojiIDs). + Column("emojis"). Exec(ctx); err != nil && err != sql.ErrNoRows { return err } } - // Delete emoji from database. + // Finally, delete emoji from database. if _, err := tx.NewDelete(). Table("emojis"). Where("? = ?", bun.Ident("id"), id). |
