Some fixes. TODO: challenge is lost if navigation to variants + back to hall. Ask...
[vchess.git] / client / src / views / Hall.vue
index 209dae3..c7dc588 100644 (file)
@@ -199,19 +199,17 @@ export default {
           {target: sid}
         )));
       };
-      if (!!to[0])
+      if (!!to)
       {
-        to.forEach(pname => {
-          // Challenge with targeted players
-          const targetSid = this.getSid(pname);
-          if (!targetSid)
-          {
-            if (!!warnDisconnected)
-              alert("Warning: " + pname + " is not connected");
-          }
-          else
-            doSend(code, obj, targetSid);
-        });
+        // Challenge with targeted players
+        const targetSid = this.getSid(to);
+        if (!targetSid)
+        {
+          if (!!warnDisconnected)
+            alert("Warning: " + pname + " is not connected");
+        }
+        else
+          doSend(code, obj, targetSid);
       }
       else
       {
@@ -403,7 +401,7 @@ export default {
       const finishAddChallenge = (cid,warnDisconnected) => {
         chall.id = cid || "c" + getRandString();
         // Send challenge to peers (if connected)
-        this.sendSomethingTo(cto, "challenge", {chall:chall}, !!warnDisconnected);
+        this.sendSomethingTo(chall.to, "challenge", {chall:chall}, !!warnDisconnected);
         chall.added = Date.now();
         chall.type = ctype;
         chall.vname = vname;
@@ -455,7 +453,7 @@ export default {
       console.log("click challenge");
       console.log(c);
 
-      else if (c.from.sid == this.st.user.sid
+      if (c.from.sid == this.st.user.sid
         || (this.st.user.id > 0 && c.from.id == this.st.user.id))
       {
         // It's my challenge: cancel it