<commit_before>import gameApi from '../../lichess/game';
import ground from './ground';
import * as xhr from './roundXhr';
import sound from '../../sound';
import session from '../../session';
import * as utils from '../../utils';
import socket from '../../socket';
import m from 'mithril';

export default function(ctrl, onFeatured) {

  var handlers = {
    takebackOffers: function(o) {
      ctrl.data.player.proposingTakeback = o[ctrl.data.player.color];
      ctrl.data.opponent.proposingTakeback = o[ctrl.data.opponent.color];
      m.redraw();
    },
    move: function(o) {
      ctrl.apiMove(o);
    },
    checkCount: function(e) {
      var isWhite = ctrl.data.player.color === 'white';
      ctrl.data.player.checks = isWhite ? e.white : e.black;
      ctrl.data.opponent.checks = isWhite ? e.black : e.white;
      m.redraw();
    },
    reload: function() {
      xhr.reload(ctrl).then(ctrl.reload);
    },
    redirect: function(e) {
      if (!ctrl.data.tv) m.route('/game/' + e.id);
    },
    resync: function() {
      xhr.reload(ctrl).then(function(data) {
        socket.setVersion(data.player.version);
        ctrl.reload(data);
      }, function(err) {
        utils.handleXhrError(err);
      });
    },
    clock: function(o) {
      if (ctrl.clock) ctrl.clock.update(o.white, o.black);
    },
    end: function(winner) {
      ctrl.data.game.winner = winner;
      ground.end(ctrl.chessground);
      xhr.reload(ctrl).then(ctrl.reload);
      if (!ctrl.data.player.spectator) sound.dong();
      window.plugins.insomnia.allowSleepAgain();
      // refresh current games card list
      if (session.isConnected()) session.refresh();
      setTimeout(function() {
        ctrl.showActions();
        m.redraw();
      }, 1000);
    },
    gone: function(isGone) {
      if (!ctrl.data.opponent.ai) {
        gameApi.setIsGone(ctrl.data, ctrl.data.opponent.color, isGone);
        if (!ctrl.chat || !ctrl.chat.showing) m.redraw();
      }
    },
    message: function(m) {
      if (ctrl.chat) ctrl.chat.append(m);
    },
    tvSelect: function(o) {
      if (ctrl.data.tv && o.channel === ctrl.data.tv && onFeatured) onFeatured(o);
    },
    crowd: function(o) {
      ['white', 'black'].forEach(function(c) {
        gameApi.setOnGame(ctrl.data, c, o[c]);
      });
      if (!ctrl.chat || !ctrl.chat.showing) m.redraw();
    }
  };

  return function(type, data) {
    if (handlers[type]) {
      handlers[type](data);
      return true;
    }
    return false;
  };
}<commit_msg>Tweak round socket<commit_after>import gameApi from '../../lichess/game';
import ground from './ground';
import * as xhr from './roundXhr';
import sound from '../../sound';
import session from '../../session';
import * as utils from '../../utils';
import socket from '../../socket';
import m from 'mithril';

export default function(ctrl, onFeatured) {

  var handlers = {
    takebackOffers: function(o) {
      ctrl.data.player.proposingTakeback = o[ctrl.data.player.color];
      ctrl.data.opponent.proposingTakeback = o[ctrl.data.opponent.color];
      m.redraw();
    },
    move: function(o) {
      ctrl.apiMove(o);
    },
    checkCount: function(e) {
      var isWhite = ctrl.data.player.color === 'white';
      ctrl.data.player.checks = isWhite ? e.white : e.black;
      ctrl.data.opponent.checks = isWhite ? e.black : e.white;
      m.redraw();
    },
    reload: function() {
      xhr.reload(ctrl).then(ctrl.reload);
    },
    redirect: function(e) {
      if (!ctrl.data.tv) m.route('/game/' + e.id);
    },
    resync: function() {
      xhr.reload(ctrl).then(function(data) {
        socket.setVersion(data.player.version);
        ctrl.reload(data);
      }, function(err) {
        utils.handleXhrError(err);
      });
    },
    clock: function(o) {
      if (ctrl.clock) ctrl.clock.update(o.white, o.black);
    },
    end: function(winner) {
      ctrl.data.game.winner = winner;
      ground.end(ctrl.chessground);
      xhr.reload(ctrl).then(ctrl.reload);
      if (!ctrl.data.player.spectator) sound.dong();
      window.plugins.insomnia.allowSleepAgain();
      // refresh current games card list
      if (session.isConnected()) session.refresh();
      setTimeout(function() {
        ctrl.showActions();
        m.redraw();
      }, 1000);
    },
    gone: function(isGone) {
      if (!ctrl.data.opponent.ai && ctrl.data.game.speed !== 'correspondence') {
        gameApi.setIsGone(ctrl.data, ctrl.data.opponent.color, isGone);
        if (!ctrl.chat || !ctrl.chat.showing) m.redraw();
      }
    },
    message: function(msg) {
      if (ctrl.chat) ctrl.chat.append(msg);
    },
    tvSelect: function(o) {
      if (ctrl.data.tv && o.channel === ctrl.data.tv && onFeatured) onFeatured(o);
    },
    crowd: function(o) {
      ['white', 'black'].forEach(function(c) {
        gameApi.setOnGame(ctrl.data, c, o[c]);
      });
      if (!ctrl.chat || !ctrl.chat.showing) m.redraw();
    }
  };

  return function(type, data) {
    if (handlers[type]) {
      handlers[type](data);
      return true;
    }
    return false;
  };
}
{'fraction_non_alphanumeric': 0.17586750788643532, 'fraction_numerical': 0.0015772870662460567, 'mean_word_length': 2.4842032967032965, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6600450', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1687, 'n_words': 312}