X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FGame.vue;h=1675c30bc8072aaa97d4d248caf807a6c5f59dcd;hb=09d375717c256a2cbd71a5d3b3a4e21aee17c0ec;hp=2da8d9e016f76f4753f93365f946872e25d0b54b;hpb=d1be804633f9632b35662c0b10743ca50e10030f;p=vchess.git diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index 2da8d9e0..1675c30b 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -24,6 +24,7 @@ main :pastChats="game.chats" :newChat="newChat" @mychat="processChat" + @chatcleared="clearChat" ) .row #aboveBoard.col-sm-12.col-md-9.col-md-offset-3.col-lg-10.col-lg-offset-2 @@ -69,6 +70,7 @@ import Chat from "@/components/Chat.vue"; import { store } from "@/store"; import { GameStorage } from "@/utils/gameStorage"; import { ppt } from "@/utils/datetime"; +import { ajax } from "@/utils/ajax"; import { extractTime } from "@/utils/timeControl"; import { getRandString } from "@/utils/alea"; import { processModalClick } from "@/utils/modalClick"; @@ -193,6 +195,25 @@ export default { Object.values(this.people).some(p => p.id == player.uid) ); }, + resetChatColor: function() { + // TODO: this is called twice, once on opening an once on closing + document.getElementById("chatBtn").classList.remove("somethingnew"); + }, + processChat: function(chat) { + this.send("newchat", { data: chat }); + // NOTE: anonymous chats in corr games are not stored on server (TODO?) + if (this.game.type == "corr" && this.st.user.id > 0) + GameStorage.update(this.gameRef.id, { chat: chat }); + }, + clearChat: function() { + // Nothing more to do if game is live (chats not recorded) + if (this.game.type == "corr") { + if (this.game.mycolor) + ajax("/chats", "DELETE", {gid: this.game.id}); + // TODO: this.game.chats = [] could be enough here? + this.$set(this.game, "chats", []); + } + }, socketMessageListener: function(msg) { if (!this.conn) return; const data = JSON.parse(msg.data); @@ -227,12 +248,12 @@ export default { break; case "killed": // I logged in elsewhere: - alert(this.st.tr["New connexion detected: tab now offline"]); // TODO: this fails. See https://github.com/websockets/ws/issues/489 //this.conn.removeEventListener("message", this.socketMessageListener); //this.conn.removeEventListener("close", this.socketCloseListener); //this.conn.close(); this.conn = null; + alert(this.st.tr["New connexion detected: tab now offline"]); break; case "askidentity": { // Request for identification (TODO: anonymous shouldn't need to reply) @@ -634,7 +655,10 @@ export default { const sendMove = { move: filtered_move, addTime: addTime, - cancelDrawOffer: this.drawOffer == "" + cancelDrawOffer: this.drawOffer == "", + // Players' SID required for /mygames page + // TODO: precompute and add this field to game object? + players: this.game.players.map(p => p.sid) }; this.send("newmove", { data: sendMove }); } @@ -717,16 +741,6 @@ export default { } else doProcessMove(); }, - resetChatColor: function() { - // TODO: this is called twice, once on opening an once on closing - document.getElementById("chatBtn").classList.remove("somethingnew"); - }, - processChat: function(chat) { - this.send("newchat", { data: chat }); - // NOTE: anonymous chats in corr games are not stored on server (TODO?) - if (this.game.type == "corr" && this.st.user.id > 0) - GameStorage.update(this.gameRef.id, { chat: chat }); - }, gameOver: function(score, scoreMsg) { this.game.score = score; this.$set(this.game, "scoreMsg", scoreMsg || getScoreMessage(score));