MyGames page is now dynamic (experimental, not much tested)
[vchess.git] / client / src / views / Hall.vue
index 4cb46ec..5217c34 100644 (file)
@@ -324,6 +324,8 @@ export default {
       params.socketUrl +
       "/?sid=" +
       this.st.user.sid +
+      "&id=" +
+      this.st.user.id +
       "&tmpId=" +
       getRandString() +
       "&page=" +
@@ -685,7 +687,7 @@ export default {
           const game = data.data;
           // Ignore games where I play (will go in MyGames page)
           if (game.players.every(p =>
-            p.sid != this.st.user.sid || p.id != this.st.user.id))
+            p.sid != this.st.user.sid || p.uid != this.st.user.id))
           {
             let locGame = this.games.find(g => g.id == game.id);
             if (!locGame) {
@@ -948,6 +950,16 @@ export default {
     },
     // NOTE: when launching game, the challenge is already being deleted
     launchGame: function(c) {
+      let players =
+        !!c.mycolor
+          ? (c.mycolor == "w" ? [c.seat, c.from] : [c.from, c.seat])
+          : shuffle([c.from, c.seat]);
+      // Convention for players IDs in stored games is 'uid'
+      players.forEach(p => {
+        let pWithUid = p;
+        pWithUid["uid"] = p.id;
+        delete pWithUid["id"];
+      });
       // These game informations will be shared
       let gameInfo = {
         id: getRandString(),
@@ -967,6 +979,16 @@ export default {
         // Send game info (only if live) to everyone except me and opponent
         // TODO: this double message send could be avoided.
         this.send("newgame", { data: gameInfo, oppsid: oppsid });
+        // Also to MyGames page:
+        this.send(
+          "notifynewgame",
+          {
+            data: gameInfo,
+            targets: gameInfo.players.map(p => {
+              return { sid: p.sid, uid: p.uid };
+            })
+          }
+        );
       };
       if (c.type == "live") {
         notifyNewgame();