summaryrefslogtreecommitdiff
path: root/internal/db
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db')
-rw-r--r--internal/db/bundb/emoji.go54
-rw-r--r--internal/db/bundb/emoji_test.go11
2 files changed, 42 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).
diff --git a/internal/db/bundb/emoji_test.go b/internal/db/bundb/emoji_test.go
index f75334d90..a4bf18f6e 100644
--- a/internal/db/bundb/emoji_test.go
+++ b/internal/db/bundb/emoji_test.go
@@ -23,6 +23,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/db"
+ "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/testrig"
)
@@ -160,6 +161,16 @@ func (suite *EmojiTestSuite) TestGetEmojiCategory() {
suite.NotNil(category)
}
+func (suite *EmojiTestSuite) TestUpdateEmojiCategory() {
+ testEmoji := new(gtsmodel.Emoji)
+ *testEmoji = *suite.testEmojis["rainbow"]
+
+ testEmoji.CategoryID = ""
+
+ err := suite.db.UpdateEmoji(context.Background(), testEmoji, "category_id")
+ suite.NoError(err)
+}
+
func TestEmojiTestSuite(t *testing.T) {
suite.Run(t, new(EmojiTestSuite))
}