- this.players.push(this.st.user);
-
- console.log("created");
-ajax("/testtest", "DELETE");
-
- // Ask server for current corr games (all but mines)
-// ajax(
-// "",
-// "GET",
-// response => {
-//
-// }
-// );
- // // Also ask for corr challenges (all) --> + accepted status if I play
-// ajax(
-// "",
-// "GET",
-// response => {
-//
-// }
-// );
+ this.people.push(this.st.user);
+ // Retrieve live challenge (not older than 30 minute) if any:
+ const chall = JSON.parse(localStorage.getItem("challenge") || "false");
+ if (!!chall)
+ {
+ if ((Date.now() - chall.added)/1000 <= 30*60)
+ this.challenges.push(chall);
+ else
+ localStorage.removeItem("challenge");
+ }
+ if (this.st.user.id > 0)
+ {
+ // Ask server for current corr games (all but mines)
+ ajax(
+ "/games",
+ "GET",
+ {uid: this.st.user.id, excluded: true},
+ response => {
+ this.games = this.games.concat(response.games);
+ }
+ );
+ // Also ask for corr challenges (open + sent to me)
+ ajax(
+ "/challenges",
+ "GET",
+ {uid: this.st.user.id},
+ response => {
+ console.log(response.challenges);
+ // TODO: post-treatment on challenges ?
+ Array.prototype.push.apply(this.challenges, response.challenges);
+ }
+ );
+ }