X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FHall.vue;h=afa2173d5af2fe3d49e707bbe46e72911a8e2a8b;hb=40477190d905a715d59a800279a20da4ef8135ed;hp=13d9b63398cb2ce07db28e89c6216d0851708275;hpb=1ba761c8fc1dafaaf8e47d08be6b38cdf0766ea3;p=vchess.git diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index 13d9b633..afa2173d 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -141,7 +141,7 @@ export default { response => { console.log(response.challenges); // TODO: post-treatment on challenges ? - this.challenges = this.challenges.concat(response.challenges); + Array.prototype.push.apply(this.challenges, response.challenges); } ); } @@ -178,6 +178,7 @@ export default { // ==> Moves sent by connected remote player(s) if live game // TODO: this doesn't work: choose a SID at random + // --> do we have players' names ? let url = "/" + g.id; if (g.type == "live") @@ -465,12 +466,14 @@ export default { console.log("click challenge"); console.log(c); - if (c.from.sid == this.st.user.sid - || (this.st.user.id > 0 && c.from.id == this.st.user.id)) + // In all cases, the challenge is consumed: + ArrayFun.remove(this.challenges, ch => ch.id == c.id); + + if (c.from.sid == this.st.user.sid //live + || (this.st.user.id > 0 && c.from.id == this.st.user.id)) //corr { // It's my challenge: cancel it this.sendSomethingTo(c.to, "deletechallenge", {cid:c.id}); - ArrayFun.remove(this.challenges, ch => ch.id == c.id); if (c.type == "corr") { ajax( @@ -491,30 +494,13 @@ export default { this.st.conn.send(JSON.stringify({ code: (c.accepted ? "accept" : "refuse") + "challenge", cid: c.id, target: c.from.sid})); - if (c.accepted) - { - if (c.type == "corr") - { - ajax( - "/challenges", - "PUT", - {id: this.challenges[cIdx].id} - ); - } - } - else + if (c.type == "corr") { - ArrayFun.remove(this.challenges, ch => ch.id == c.id); - if (!c.to) //TODO: send to everyone except me and opponent ? - this.sendSomethingTo("", "deletechallenge", {cid: this.challenges[cIdx].id}); - if (c.type == "corr") - { - ajax( - "/challenges", - "DELETE", - {id: this.challenges[cIdx].id} - ); - } + ajax( + "/challenges", + accepted ? "PUT" : "DELETE", + {id: this.challenges[cIdx].id} + ); } } },