Remove unused move.color, format moves corr --> live after retrieval
[vchess.git] / server / routes / games.js
index 73a8bf7..9bd9a30 100644 (file)
@@ -34,7 +34,7 @@ router.get("/games", access.ajax, (req,res) => {
   {
     GameModel.getOne(gameId, (err,game) => {
                  access.checkRequest(res, err, game, "Game not found", () => {
-                         res.json({game: game});
+        res.json({game: game});
                  });
          });
   }
@@ -54,13 +54,19 @@ router.get("/games", access.ajax, (req,res) => {
 // New move + fen update + score, potentially
 // TODO: if newmove fail, takeback in GUI
 router.put("/games", access.logged, access.ajax, (req,res) => {
-       const gid = req.body.gid;
+  const gid = req.body.gid;
        const obj = req.body.newObj;
        GameModel.update(gid, obj, (err) => {
                if (!!err)
       return res.json(err);
-    if (!!req.body.offlineOpp) //TODO: refresh this...
-      UserModel.tryNotify(req.body.offlineOpp, "New move in game " + gid);
+    // Notify opponent if he enabled notifications:
+    GameModel.getPlayers(gid, (err2,players) => {
+      if (!!err2)
+        return res.json(err);
+      const oppid = (players[0].id == req.userId ? players[1].id : players[0].id);
+      UserModel.tryNotify(oppid,
+        "New move in game: " + params.siteURL + "/game/" + gid);
+    });
     res.json({});
        });
 });