Skip to content

Commit

Permalink
fix(pins)_: remove pins when the original message is deleted
Browse files Browse the repository at this point in the history
Fixes #6246
  • Loading branch information
jrainville committed Jan 10, 2025
1 parent a45bc19 commit 72a72bc
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion protocol/message_persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,13 @@ func (db sqlitePersistence) SavePinMessage(message *common.PinMessage) (inserted

func (db sqlitePersistence) DeleteMessage(id string) error {
_, err := db.db.Exec(`DELETE FROM user_messages WHERE id = ?`, id)

if err != nil {
return err
}

_, err = db.db.Exec("DELETE FROM pin_messages WHERE message_id = ?", id)

return err
}

Expand All @@ -1778,7 +1785,25 @@ func (db sqlitePersistence) DeleteMessages(ids []string) error {
}
inVector := strings.Repeat("?, ", len(ids)-1) + "?"

_, err := db.db.Exec("DELETE FROM user_messages WHERE id IN ("+inVector+")", idsArgs...) // nolint: gosec
tx, err := db.db.BeginTx(context.Background(), &sql.TxOptions{})
if err != nil {
return err
}
defer func() {
if err == nil {
err = tx.Commit()
return
}
// don't shadow original error
_ = tx.Rollback()
}()

_, err = tx.Exec("DELETE FROM user_messages WHERE id IN ("+inVector+")", idsArgs...) // nolint: gosec
if err != nil {
return err
}

_, err = tx.Exec("DELETE FROM pin_messages WHERE message_id IN ("+inVector+")", idsArgs...) // nolint: gosec

return err
}
Expand Down

0 comments on commit 72a72bc

Please sign in to comment.