From: Benjamin Auder Date: Wed, 4 Mar 2020 22:04:24 +0000 (+0100) Subject: Fix targetted challenge deletion after refusal X-Git-Url: https://git.auder.net/doc/html/css/current/scripts/pieces/R.css?a=commitdiff_plain;h=1511c610b30e524a95c45c8fa263275ec3013101;p=vchess.git Fix targetted challenge deletion after refusal --- diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index 8d8b311a..5cbe0c86 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -812,6 +812,8 @@ export default { const oppsid = this.getOppsid(c); if (oppsid) this.send("refusechallenge", { data: c.id, target: oppsid }); + if (c.type == "corr") + ajax("/challenges", "DELETE", { id: c.id }); } this.send("deletechallenge", { data: c.id }); }, @@ -850,9 +852,8 @@ export default { } else { // My challenge - if (c.type == "corr") { + if (c.type == "corr") ajax("/challenges", "DELETE", { id: c.id }); - } this.send("deletechallenge", { data: c.id }); } // In all cases, the challenge is consumed: diff --git a/server/models/Challenge.js b/server/models/Challenge.js index 243da709..40d125c9 100644 --- a/server/models/Challenge.js +++ b/server/models/Challenge.js @@ -74,7 +74,9 @@ const ChallengeModel = const query = "SELECT 1 " + "FROM Challenges " + - "WHERE id = " + id + " AND uid = " + uid; + "WHERE id = " + id + " " + + // Condition: I'm the sender or the target + "AND (uid = " + uid + " OR to = " + uid + ")"; db.get(query, (err,chall) => { if (!err && chall) ChallengeModel.remove(id);