X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fcomponents%2FChat.vue;h=bce0ba0df5b52491ee7972cc323c3c2a94dc2330;hb=e6ca903027ba7c4867393ac8fe8c58b5fa6e0efe;hp=6eb7ef31bcb7442b3326d89fd63125ec9aa46c4b;hpb=3b959cfaf3d3a28373d7ebb48d80087150a98006;p=vchess.git diff --git a/client/src/components/Chat.vue b/client/src/components/Chat.vue index 6eb7ef31..bce0ba0d 100644 --- a/client/src/components/Chat.vue +++ b/client/src/components/Chat.vue @@ -9,7 +9,7 @@ div ) button(@click="sendChat()") {{ st.tr["Send"] }} p(v-for="chat in chats.concat(pastChats)") - span.name {{ chat.name }} :  + span.name {{ chat.name || "@nonymous" }} :  span( :class="classObject(chat)" v-html="chat.msg" @@ -21,39 +21,59 @@ 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 { - "my-chatmsg": chat.name == this.st.user.name, + "my-chatmsg": ( + !!chat.name && chat.name == this.st.user.name || + !!chat.sid && chat.sid == this.st.user.sid + ), "opp-chatmsg": !!this.players && this.players.some( - p => p.name == chat.name && p.name != this.st.user.name + p => { + return ( + ( + !!p.name && + p.name == chat.name && + p.name != this.st.user.name + ) + || + ( + !!p.sid && + p.sid == chat.sid && + p.sid != this.st.user.sid + ) + ); + } ) }; }, sendChat: function() { let chatInput = document.getElementById("inputChat"); const chatTxt = chatInput.value.trim(); + chatInput.focus(); //required on smartphones if (chatTxt == "") return; //nothing to send chatInput.value = ""; - const chat = { msg: chatTxt, name: this.st.user.name || "@nonymous" }; + const chat = { + msg: chatTxt, + name: this.st.user.name, + // SID is required only for anonymous users (in live games) + sid: this.st.user.id == 0 ? this.st.user.sid : null + }; this.$emit("mychat", chat); this.chats.unshift(chat); }, + newChat: function(chat) { + if (chat.msg != "") this.chats.unshift(chat); + }, clearHistory: function() { this.chats = []; this.$emit("chatcleared"); @@ -64,10 +84,10 @@ export default {