chore: improve label status handling
This commit is contained in:
@@ -228,11 +228,15 @@ func (a *App) handleDeleteMailLabel(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
tx, err := a.db.BeginTx(ctx, nil)
|
if !a.labelBelongsToMailbox(ctx, labelID, mb.ID) {
|
||||||
if err != nil {
|
respondError(w, http.StatusNotFound, "label not found")
|
||||||
respondError(w, http.StatusInternalServerError, "failed to begin transaction")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
tx, err := a.db.BeginTx(ctx, nil)
|
||||||
|
if (_, err := tx.ExecContext(ctx, "DELETE FROM message_labels WHERE label_id = ? AND EXISTS (SELECT 1 FROM mail_labels WHERE id = ? AND mailbox_id = ?)", labelID, labelID, mb.ID); err != nil {
|
||||||
|
respondError(w, http.StatusInternalServerError, "failed to remove label associations")
|
||||||
|
return
|
||||||
|
}
|
||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
if _, err := tx.ExecContext(ctx, `DELETE FROM message_labels WHERE label_id=?`, labelID); err != nil {
|
if _, err := tx.ExecContext(ctx, `DELETE FROM message_labels WHERE label_id=?`, labelID); err != nil {
|
||||||
respondError(w, http.StatusInternalServerError, "failed to remove label associations")
|
respondError(w, http.StatusInternalServerError, "failed to remove label associations")
|
||||||
|
|||||||
Reference in New Issue
Block a user