<commit_before>'use strict';

/**
 * @ngdoc function
 * @name answerAThingApp.controller:RoomController
 * @description
 * # RoomController
 * Controller of the answerAThingApp
 */
angular.module('answerAThingApp')
  .controller('RoomController', function ($scope, drawSocket, gameState, $interval) {
    $scope.gameState = gameState;
    $scope.error = false;
    $scope.leaveRoom = function() {
      drawSocket.emit('user.leaveRoom', {});
    };
    $scope.startGame = function() {
      drawSocket.emit('room.startGame', {});
    };
    $scope.progress = function(data) {
      $scope.drawboard = data;
      drawSocket.emit('user.drawboard', {drawboard: data} );
    };
    $scope.submit = function(data) {
      $scope.drawboard = data;
      drawSocket.emit('user.drawboard', {drawboard: data} );
      drawSocket.emit('room.submitAnswer', {});
    };
    $scope.selectQuestion = function(questionIndex) {
      drawSocket.emit('room.selectQuestion', {questionIndex: questionIndex} );
    };
    $scope.selectAnswer = function(username) {
      drawSocket.emit('room.selectAnswer', {username: username});
    };
    $scope.isCaller = function() {
      return gameState.user.hasOwnProperty('room') && gameState.user.room.hasOwnProperty('caller') && gameState.user.username === gameState.user.room.caller;
    };
    $scope.cantDraw = function() {
      var cantDrawStates = ['playersBet', 'callerSelectAnswer', 'results'];
      return gameState.user.hasOwnProperty('room') && cantDrawStates.indexOf(gameState.user.room.state.status) > -1;
    };
    $scope.betOnUser = function(username) {
      drawSocket.emit('room.betOnUser', {username: username});
    };
    $scope.clickHandler = function(username) {
      if ($scope.isCaller()) {
        $scope.selectAnswer(username);
      }
      else {
        $scope.betOnUser(username);
      }
    };
    var stop;
    $interval(function() {
      if (gameState.user.room.state.timerEnd)
        $scope.timeLeft = Math.floor((gameState.user.room.state.timerEnd - Date.now()) / 1000);
      else
        $scope.timeLeft = 0
    }, 1000);
    $scope.$on('$destroy', function() {
      if (angular.isDefined(stop)) {
        $interval.cancel(stop);
      }
    });
    $scope.isArray = angular.isArray;
    drawSocket.on('error', function(error) {
      $scope.error = error;
    });
    drawSocket.emit('room.getDrawboards', {});
  });<commit_msg>checking to make sure we're in a room before checking the state of it<commit_after>'use strict';

/**
 * @ngdoc function
 * @name answerAThingApp.controller:RoomController
 * @description
 * # RoomController
 * Controller of the answerAThingApp
 */
angular.module('answerAThingApp')
  .controller('RoomController', function ($scope, drawSocket, gameState, $interval) {
    $scope.gameState = gameState;
    $scope.error = false;
    $scope.leaveRoom = function() {
      drawSocket.emit('user.leaveRoom', {});
    };
    $scope.startGame = function() {
      drawSocket.emit('room.startGame', {});
    };
    $scope.progress = function(data) {
      $scope.drawboard = data;
      drawSocket.emit('user.drawboard', {drawboard: data} );
    };
    $scope.submit = function(data) {
      $scope.drawboard = data;
      drawSocket.emit('user.drawboard', {drawboard: data} );
      drawSocket.emit('room.submitAnswer', {});
    };
    $scope.selectQuestion = function(questionIndex) {
      drawSocket.emit('room.selectQuestion', {questionIndex: questionIndex} );
    };
    $scope.selectAnswer = function(username) {
      drawSocket.emit('room.selectAnswer', {username: username});
    };
    $scope.isCaller = function() {
      return gameState.user.hasOwnProperty('room') && gameState.user.room.hasOwnProperty('caller') && gameState.user.username === gameState.user.room.caller;
    };
    $scope.cantDraw = function() {
      var cantDrawStates = ['playersBet', 'callerSelectAnswer', 'results'];
      return gameState.user.hasOwnProperty('room') && cantDrawStates.indexOf(gameState.user.room.state.status) > -1;
    };
    $scope.betOnUser = function(username) {
      drawSocket.emit('room.betOnUser', {username: username});
    };
    $scope.clickHandler = function(username) {
      if ($scope.isCaller()) {
        $scope.selectAnswer(username);
      }
      else {
        $scope.betOnUser(username);
      }
    };
    var stop;
    $interval(function() {
      if (gameState.user.room && gameState.user.room.state.timerEnd)
        $scope.timeLeft = Math.floor((gameState.user.room.state.timerEnd - Date.now()) / 1000);
      else
        $scope.timeLeft = 0
    }, 1000);
    $scope.$on('$destroy', function() {
      if (angular.isDefined(stop)) {
        $interval.cancel(stop);
      }
    });
    $scope.isArray = angular.isArray;
    drawSocket.on('error', function(error) {
      $scope.error = error;
    });
    drawSocket.emit('room.getDrawboards', {});
  });
{'fraction_non_alphanumeric': 0.16205695554189714, 'fraction_numerical': 0.004097520999795124, 'mean_word_length': 3.2231833910034604, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2622858', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1497, 'n_words': 232}