summaryrefslogtreecommitdiff
path: root/internal/db/bundb
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/bundb')
-rw-r--r--internal/db/bundb/bundb_test.go2
-rw-r--r--internal/db/bundb/emoji.go37
-rw-r--r--internal/db/bundb/emoji_test.go11
3 files changed, 50 insertions, 0 deletions
diff --git a/internal/db/bundb/bundb_test.go b/internal/db/bundb/bundb_test.go
index 2af6cf122..b05df8b74 100644
--- a/internal/db/bundb/bundb_test.go
+++ b/internal/db/bundb/bundb_test.go
@@ -41,6 +41,7 @@ type BunDBStandardTestSuite struct {
testTags map[string]*gtsmodel.Tag
testMentions map[string]*gtsmodel.Mention
testFollows map[string]*gtsmodel.Follow
+ testEmojis map[string]*gtsmodel.Emoji
}
func (suite *BunDBStandardTestSuite) SetupSuite() {
@@ -54,6 +55,7 @@ func (suite *BunDBStandardTestSuite) SetupSuite() {
suite.testTags = testrig.NewTestTags()
suite.testMentions = testrig.NewTestMentions()
suite.testFollows = testrig.NewTestFollows()
+ suite.testEmojis = testrig.NewTestEmojis()
}
func (suite *BunDBStandardTestSuite) SetupTest() {
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{}
diff --git a/internal/db/bundb/emoji_test.go b/internal/db/bundb/emoji_test.go
index c6577a721..b542f9b67 100644
--- a/internal/db/bundb/emoji_test.go
+++ b/internal/db/bundb/emoji_test.go
@@ -38,6 +38,17 @@ func (suite *EmojiTestSuite) TestGetUseableEmojis() {
suite.Equal("rainbow", emojis[0].Shortcode)
}
+func (suite *EmojiTestSuite) TestDeleteEmojiByID() {
+ testEmoji := suite.testEmojis["rainbow"]
+
+ err := suite.db.DeleteEmojiByID(context.Background(), testEmoji.ID)
+ suite.NoError(err)
+
+ dbEmoji, err := suite.db.GetEmojiByID(context.Background(), testEmoji.ID)
+ suite.Nil(dbEmoji)
+ suite.ErrorIs(err, db.ErrNoEntries)
+}
+
func (suite *EmojiTestSuite) TestGetEmojiByStaticURL() {
emoji, err := suite.db.GetEmojiByStaticURL(context.Background(), "http://localhost:8080/fileserver/01F8MH17FWEB39HZJ76B6VXSKF/emoji/static/01F8MH9H8E4VG3KDYJR9EGPXCQ.png")
suite.NoError(err)