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 {
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");
| {{ st.tr["Rematch in progress"] }}
input#modalChat.modal(
type="checkbox"
- @click="resetChatColor()"
+ @click="toggleChat()"
)
div#chatWrap(
role="dialog"
ref="chatcomp"
:players="game.players"
:pastChats="game.chats"
- :newChat="newChat"
@mychat="processChat"
@chatcleared="clearChat"
)
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:
this.lastateAsked = false;
this.rematchOffer = "";
this.lastate = undefined;
- this.newChat = "";
this.roomInitialized = false;
this.askGameTime = 0;
this.gameIsLoading = false;
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) {
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;
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) {
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
fen: this.game.fen,
move: {
squares: filtered_move,
- played: Date.now(),
idx: origMovescount
},
// Code "n" for "None" to force reset (otherwise it's ignored)