projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix capturing promotions in Absorption variant
[vchess.git]
/
client
/
src
/
components
/
Chat.vue
diff --git
a/client/src/components/Chat.vue
b/client/src/components/Chat.vue
index
f1e1fad
..
bce0ba0
100644
(file)
--- a/
client/src/components/Chat.vue
+++ b/
client/src/components/Chat.vue
@@
-1,5
+1,7
@@
<template lang="pug">
div
<template lang="pug">
div
+ button(@click="clearHistory()")
+ | {{ st.tr["Clear history"] }}
input#inputChat(
type="text"
:placeholder="st.tr['Chat here']"
input#inputChat(
type="text"
:placeholder="st.tr['Chat here']"
@@
-7,7
+9,7
@@
div
)
button(@click="sendChat()") {{ st.tr["Send"] }}
p(v-for="chat in chats.concat(pastChats)")
)
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"
span(
:class="classObject(chat)"
v-html="chat.msg"
@@
-19,38
+21,62
@@
import { store } from "@/store";
export default {
name: "my-chat",
// Prop 'pastChats' for corr games where chats are on server
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
};
},
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 {
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(
"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();
)
};
},
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 = "";
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);
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");
}
}
};
}
}
};
@@
-58,10
+84,10
@@
export default {
<style lang="sass" scoped>
.name
<style lang="sass" scoped>
.name
- color: #
abb2b9
+ color: #
839192
.my-chatmsg
.my-chatmsg
- color: #
7d3c98
+ color: #
6c3483
.opp-chatmsg
.opp-chatmsg
- color: #
2471a3
+ color: #
1f618d
</style>
</style>