import Messaging; import player from Room; import Save; import Session; import Table; import Time; var entries = Table.make(function(o) {return o.value.date;}); entries.insertAll(Save.get('games.entry') || {}); initMessageHandlers(); return { entries: entries, proposal: proposal }; function makeEntry(state) { var sessionKey = Session.getKey(); return Time.timestamp({ vs: player(state.public.nextPlayer[sessionKey]), yourTurn: state.public.playing == sessionKey }); } function proposal(playerID, yourTurn) { entries.insert( playerID, Time.timestamp({vs: player(playerID), yourTurn: yourTurn}) ); } function initMessageHandlers() { Messaging.addEventListener(["Game"], function(o) { var gameID = o.state.public.gameState.gameID; var entry = makeEntry(o.state); Save.set("games.message." + gameID, o); Save.set("games.entry." + gameID, entry); entries.insert(gameID, entry); }); }