chore: improve label status handling

This commit is contained in:
killerprojecte
2026-06-22 14:11:11 +08:00
parent 94ab94eceb
commit 8d29dbd126
+6 -2
View File
@@ -228,9 +228,13 @@ func (a *App) handleDeleteMailLabel(w http.ResponseWriter, r *http.Request) {
return
}
ctx := r.Context()
if !a.labelBelongsToMailbox(ctx, labelID, mb.ID) {
respondError(w, http.StatusNotFound, "label not found")
return
}
tx, err := a.db.BeginTx(ctx, nil)
if err != nil {
respondError(w, http.StatusInternalServerError, "failed to begin transaction")
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()