Fix targetted challenge deletion after refusal
authorBenjamin Auder <benjamin.auder@somewhere>
Wed, 4 Mar 2020 22:04:24 +0000 (23:04 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Wed, 4 Mar 2020 22:04:24 +0000 (23:04 +0100)
client/src/views/Hall.vue
server/models/Challenge.js

index 8d8b311..5cbe0c8 100644 (file)
@@ -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:
index 243da70..40d125c 100644 (file)
@@ -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);