+ 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.type == "corr") {
+ if (this.game.mycolor)
+ ajax("/chats", "DELETE", {gid: this.game.id});
+ this.game.chats = [];
+ }
+ },
+ // Notify turn after a new move (to opponent and me on MyGames page)
+ notifyTurn: function(sid) {
+ const player = this.people[sid];
+ const colorIdx = this.game.players.findIndex(
+ p => p.sid == sid || p.id == player.id);
+ const color = ["w","b"][colorIdx];
+ const yourTurn =
+ (
+ color == "w" &&
+ this.game.movesCount % 2 == 0
+ )
+ ||
+ (
+ color == "b" &&
+ this.game.movesCount % 2 == 1
+ );
+ this.send("turnchange", { target: sid, yourTurn: yourTurn });
+ },