: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
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.mycolor && this.game.type == "corr") {
+ ajax(
+ "/chats",
+ "DELETE",
+ {gid: this.game.id},
+ () => {
+ // TODO: this.game.pastChats = [] could be enough here?
+ this.$set(this.game, "pastChats", []);
+ }
+ );
+ }
+ },
socketMessageListener: function(msg) {
if (!this.conn) return;
const data = JSON.parse(msg.data);
break;
case "fullgame":
// Callback "roomInit" to poll clients only after game is loaded
- this.loadGame(data.data, this.roomInit);
+ let game = data.data;
+ // Move format isn't the same in storage and in browser,
+ // because of the 'addTime' field.
+ game.moves = game.moves.map(m => { return m.move || m; });
+ this.loadGame(game, this.roomInit);
break;
case "asklastate":
// Sending last state if I played a move or score != "*"
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 });
}
}
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));