<commit_before>import * as utils from '../utils';
import { challenge as challengeXhr } from '../xhr';
import settings from '../settings';
import session from '../session';
import formWidgets from './shared/form';
import popupWidget from './shared/popup';
import i18n from '../i18n';
import storage from '../storage';
import backbutton from '../backbutton';
import ViewOnlyBoard from './shared/ViewOnlyBoard';
import helper from './helper';
import m from 'mithril';

var challengeForm = {
  actionName: '',
  userId: null,
  isOpen: false
};

challengeForm.open = function(userId) {
  if (userId) {
    challengeForm.userId = userId;
    challengeForm.actionName = i18n('challengeToPlay');
  } else {
    challengeForm.userId = null;
    challengeForm.actionName = i18n('playWithAFriend');
  }
  backbutton.stack.push(challengeForm.close);
  challengeForm.isOpen = true;
  challengeForm.fen = null;
};

challengeForm.openFromPosition = function(fen) {
  challengeForm.userId = null;
  settings.gameSetup.challenge.variant('3');
  settings.gameSetup.challenge.mode('0');
  challengeForm.open();
  challengeForm.fen = fen;
};

challengeForm.close = function(fromBB) {
  if (fromBB !== 'backbutton' && challengeForm.isOpen) backbutton.stack.pop();
  challengeForm.isOpen = false;
};

function challenge() {
  const userId = challengeForm.userId;
  return challengeXhr(userId, challengeForm.fen).then(data => {
    if (session.isConnected() &&
      !storage.get('donotshowpersistentchallengeexplanation') && (
      data.challenge.timeControl.type === 'correspondence' ||
      data.challenge.timeControl.type === 'unlimited')) {
      window.navigator.notification.alert(i18n('persistentChallengeCreated'), function() {
        storage.set('donotshowpersistentchallengeexplanation', true);
      });
      m.route('/correspondence', { tab: 'challenges' });
    }
    if (!data.challenge.destUser || data.challenge.timeControl.type === 'clock') {
      m.route(`/challenge/${data.challenge.id}`);
    }
  }, error => {
    utils.handleXhrError(error);
    throw error;
  });
}

function renderForm() {
  var formName = 'invite';
  var settingsObj = settings.gameSetup.challenge;
  var variants = settings.gameSetup.challenge.availableVariants;
  var timeModes = settings.gameSetup.challenge.availableTimeModes;
  var timeMode = settingsObj.timeMode();
  var hasClock = timeMode === '1';
  var hasDays = timeMode === '2';<commit_msg>Always redirect to challenge view<commit_after>import * as utils from '../utils';
import { challenge as challengeXhr } from '../xhr';
import settings from '../settings';
import session from '../session';
import formWidgets from './shared/form';
import popupWidget from './shared/popup';
import i18n from '../i18n';
import storage from '../storage';
import backbutton from '../backbutton';
import ViewOnlyBoard from './shared/ViewOnlyBoard';
import helper from './helper';
import m from 'mithril';

var challengeForm = {
  actionName: '',
  userId: null,
  isOpen: false
};

challengeForm.open = function(userId) {
  if (userId) {
    challengeForm.userId = userId;
    challengeForm.actionName = i18n('challengeToPlay');
  } else {
    challengeForm.userId = null;
    challengeForm.actionName = i18n('playWithAFriend');
  }
  backbutton.stack.push(challengeForm.close);
  challengeForm.isOpen = true;
  challengeForm.fen = null;
};

challengeForm.openFromPosition = function(fen) {
  challengeForm.userId = null;
  settings.gameSetup.challenge.variant('3');
  settings.gameSetup.challenge.mode('0');
  challengeForm.open();
  challengeForm.fen = fen;
};

challengeForm.close = function(fromBB) {
  if (fromBB !== 'backbutton' && challengeForm.isOpen) backbutton.stack.pop();
  challengeForm.isOpen = false;
};

function challenge() {
  const userId = challengeForm.userId;
  return challengeXhr(userId, challengeForm.fen).then(data => {
    if (session.isConnected() && (
      data.challenge.timeControl.type === 'correspondence' ||
      data.challenge.timeControl.type === 'unlimited')) {

      if (!storage.get('donotshowpersistentchallengeexplanation')) {
        window.navigator.notification.alert(i18n('persistentChallengeCreated'), function() {
          storage.set('donotshowpersistentchallengeexplanation', true);
        });
      }
      m.route('/correspondence', { tab: 'challenges' });
    }
    if (!data.challenge.destUser || data.challenge.timeControl.type === 'clock') {
      m.route(`/challenge/${data.challenge.id}`);
    }
  }, error => {
    utils.handleXhrError(error);
    throw error;
  });
}

function renderForm() {
  var formName = 'invite';
  var settingsObj = settings.gameSetup.challenge;
  var variants = settings.gameSetup.challenge.availableVariants;
  var timeModes = settings.gameSetup.challenge.availableTimeModes;
  var timeMode = settingsObj.timeMode();
  var hasClock = timeMode === '1';
  var hasDays = timeMode === '2';
{'fraction_non_alphanumeric': 0.1470888661899898, 'fraction_numerical': 0.005720122574055159, 'mean_word_length': 4.219616204690832, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3933175', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1454, 'n_words': 304}