From 8be8238cbd8bd1eeeb4c101648d6902cae425f7b Mon Sep 17 00:00:00 2001 From: Benjamin Auder Date: Tue, 17 Mar 2020 14:59:57 +0100 Subject: [PATCH] A few fixes --- client/src/components/Chat.vue | 12 +++++------- client/src/views/Game.vue | 23 +++++++++++------------ server/models/Game.js | 5 +---- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/client/src/components/Chat.vue b/client/src/components/Chat.vue index 6eb7ef31..510acdda 100644 --- a/client/src/components/Chat.vue +++ b/client/src/components/Chat.vue @@ -21,19 +21,13 @@ import { store } from "@/store"; export default { name: "my-chat", // Prop 'pastChats' for corr games where chats are on server - props: ["players", "pastChats", "newChat"], + props: ["players", "pastChats"], data: function() { return { st: store.state, chats: [] //chat messages after human game }; }, - watch: { - newChat: function(chat) { - if (chat.msg != "") - this.chats.unshift({ msg: chat.msg, name: chat.name || "@nonymous" }); - } - }, methods: { classObject: function(chat) { return { @@ -54,6 +48,10 @@ export default { this.$emit("mychat", chat); this.chats.unshift(chat); }, + newChat: function(chat) { + if (chat.msg != "") + this.chats.unshift({ msg: chat.msg, name: chat.name || "@nonymous" }); + }, clearHistory: function() { this.chats = []; this.$emit("chatcleared"); diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index 0182352a..bceb361c 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -14,7 +14,7 @@ main | {{ st.tr["Rematch in progress"] }} input#modalChat.modal( type="checkbox" - @click="resetChatColor()" + @click="toggleChat()" ) div#chatWrap( role="dialog" @@ -37,7 +37,6 @@ main ref="chatcomp" :players="game.players" :pastChats="game.chats" - :newChat="newChat" @mychat="processChat" @chatcleared="clearChat" ) @@ -172,7 +171,6 @@ export default { lastate: undefined, //used if opponent send lastate before game is ready repeat: {}, //detect position repetition curDiag: "", //for corr moves confirmation - newChat: "", conn: null, roomInitialized: false, // If newmove has wrong index: ask fullgame again: @@ -276,7 +274,6 @@ export default { this.lastateAsked = false; this.rematchOffer = ""; this.lastate = undefined; - this.newChat = ""; this.roomInitialized = false; this.askGameTime = 0; this.gameIsLoading = false; @@ -380,8 +377,12 @@ export default { if (!!oppsid && !!this.people[oppsid]) return oppsid; return null; }, - resetChatColor: function() { - // TODO: this is called twice, once on opening an once on closing + toggleChat: function() { + if (document.getElementById("modalChat").checked) + // Entering chat + document.getElementById("inputChat").focus(); + // TODO: next line is only required when exiting chat, + // but the event for now isn't well detected. document.getElementById("chatBtn").classList.remove("somethingnew"); }, processChat: function(chat) { @@ -711,7 +712,7 @@ export default { break; } case "newchat": - this.newChat = data.data; + this.$refs["chatcomp"].newChat(data.data); if (!document.getElementById("modalChat").checked) document.getElementById("chatBtn").classList.add("somethingnew"); break; @@ -1025,7 +1026,7 @@ export default { oppsid: myIdx < 0 ? undefined : game.players[1 - myIdx].sid, oppid: myIdx < 0 ? undefined : game.players[1 - myIdx].id }, - game, + game ); this.$refs["basegame"].re_setVariables(this.game); if (!this.gameIsLoading) { @@ -1160,9 +1161,8 @@ export default { if (this.game.type == "live") { if (!!data.clock) this.game.clocks[colorIdx] = data.clock; else this.game.clocks[colorIdx] += addTime; - } - // In corr games, just reset clock to mainTime: - else { + } else { + // In corr games, just reset clock to mainTime: this.game.clocks[colorIdx] = extractTime(this.game.cadence).mainTime; } // NOTE: opponent's initime is reset after "gotmove" is received @@ -1220,7 +1220,6 @@ export default { fen: this.game.fen, move: { squares: filtered_move, - played: Date.now(), idx: origMovescount }, // Code "n" for "None" to force reset (otherwise it's ignored) diff --git a/server/models/Game.js b/server/models/Game.js index 641c0dce..5f332b75 100644 --- a/server/models/Game.js +++ b/server/models/Game.js @@ -300,10 +300,7 @@ const GameModel = // Check all that is possible (required) in obj: return ( ( - !obj.move || ( - !!(obj.move.played.toString().match(/^[0-9]+$/)) && - !!(obj.move.idx.toString().match(/^[0-9]+$/)) - ) + !obj.move || !!(obj.move.idx.toString().match(/^[0-9]+$/)) ) && ( !obj.drawOffer || !!(obj.drawOffer.match(/^[wbtn]$/)) ) && ( -- 2.44.0