Delete messages from chat when leaving org

This commit is contained in:
Andrea Maria Piana 2020-12-22 16:39:05 +01:00
parent b4905fdbd4
commit f3afa962c6
1 changed files with 22 additions and 3 deletions

View File

@ -158,9 +158,28 @@ func (db sqlitePersistence) saveChat(tx *sql.Tx, chat Chat) error {
return err
}
func (db sqlitePersistence) DeleteChat(chatID string) error {
_, err := db.db.Exec("DELETE FROM chats WHERE id = ?", chatID)
return err
func (db sqlitePersistence) DeleteChat(chatID string) (err error) {
var tx *sql.Tx
tx, err = db.db.BeginTx(context.Background(), &sql.TxOptions{})
if err != nil {
return
}
defer func() {
if err == nil {
err = tx.Commit()
return
}
// don't shadow original error
_ = tx.Rollback()
}()
_, err = tx.Exec("DELETE FROM chats WHERE id = ?", chatID)
if err != nil {
return
}
_, err := tx.Exec(`DELETE FROM user_messages WHERE local_chat_id = ?`, chatID)
return
}
func (db sqlitePersistence) MuteChat(chatID string) error {