<commit_before>(function () {
	'use strict';
	
	/**
	 * @ngdoc overview
	 * @name app
	 * @description
	 * # The...
	 */
	angular.module('app')
		.controller('RecieverController', RecieverController);

	RecieverController.$inject = ['$scope', '$modal', '$log', 'ThoughtSocket',
		'UserService', '$location', '$routeParams', '$rootScope', '$timeout',
		'toastr', '$animate', 'LoggerService'];
	function RecieverController($scope, $modal, $log, ThoughtSocket,
		UserService, $location, $routeParams, $rootScope, $timeout, 
	 toastr, $animate, Logger) {

		(function initController() {
			$scope.participantThoughts = [];
			$scope.prompt = {};
			$scope.numSubmitters = 0;
			$scope.numConnected = 0;
			$scope.dataLoading = true;
			$scope.ngmSettings = {
        	    closeEl: '.close',
        	    overlay: {
        	        templateUrl: 'facilitator/thoughtOverlay.html'
        	    }
        	};

			ThoughtSocket.emit('facilitator-join', {
				groupId: $routeParams.groupId,
				userId: UserService.user.id
			});

			$scope.BG_COLORS = {
				// 1: 'red',
				// 2: 'orange',
			};

			ThoughtSocket.on('group-colors', function (colors) {
        console.log('group-colors', colors);
        colors.forEach(function (color) {
        	$scope.BG_COLORS[color.id] = color;
        });
      });

		})();

		// TEMP METHOD: Test thoughts - adds some thoughts automatically to the
		// teacher view for ui testing.
		$scope.testThoughts = function () {
			console.log("got testThoughts cmd");
			for (var i = 0; i < 16; i++) {
				Logger.createEvent({
					data: 'content: ' + i + " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
				});
				$scope.participantThoughts.push({
					localIdx: $scope.participantThoughts.length,
					content: i + " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
				});
			}
		};

		$scope.animatedBounce = function (elemId) {
			$animate.addClass($(elemId), 'animated bounce')
				.then(function () {
					$timeout(function () {
						$animate.removeClass($('#numConnected'),'animated bounce');
					}, 1000);
				});
		};

		$scope.$watch('participantThoughts.length', function (nv, ov) {
			if (nv !== ov) {
				$scope.animatedBounce('#numThoughts');
			}
		});

		$scope.$watch('numSubmitters', function (nv, ov) {
			if (nv !== ov) {
				$scope.animatedBounce('#numSubmitters');
			}
		});

		$scope.$watch('numConnected', function (nv, ov) {
			if (nv !== ov) {
				$scope.animatedBounce('#numConnected');
			}
		});

		$scope.thoughtMoved = function (idx) {
			$scope.participantThoughts.splice(idx, 1);
			$scope.updateLocalIdx();
		};

		ThoughtSocket.on('facilitator-prompt', function (data) {
			console.log('facilitator-prompt', data);
			$scope.prompt = data;
			$scope.participantThoughts = [];
			toastr.success('', 'New Prompt Created');
		});

		ThoughtSocket.on('participant-join', function () {
			console.log('participant-join');
			$scope.numConnected++;
		});

		ThoughtSocket.on('participant-leave', function () {
			console.log('participant-leave');
			$scope.numConnected--;
		});

		ThoughtSocket.on('sessionsyncres', function (data) {
			console.log('Recieved session sync response:', data);
			// $scope.participantThoughts = data.prompt.get('thoughts'); //TODO: at somepoint sync should send us the existing thoughts if we're late joining
			$scope.prompt = data.prompt;
			$scope.sessionId = data.sessionId;
			if (data.prompt.hasOwnProperty('thoughts') && data.prompt.thoughts && data.prompt.thoughts.isArray()) {
				$scope.participantThoughts = data.prompt.thoughts;
			}
			// $scope.numThoughts = data.prompt.thoughts.length();
			// $scope.numSubmitters = ?
		});

		$scope.newSession = function () {
			$scope.participantThoughts = [];
			//$scope.numThoughts = 0;
			$scope.numSubmitters = 0;
			ThoughtSocket.emit('session-sync-req', {
				userId: UserService.user.id,
				groupId: $routeParams.groupId,
				sessionId: $scope.sessionId
			});
			Logger.createEvent({
				data: 'new session for group: ' + $routeParams.groupId,
				type: 'newSession'
			});
			toastr.success('', 'Started New Session');
		};

		ThoughtSocket.on('new-session-prompt', function (prompt) {
			console.log("Got data in new-session-prompt", prompt);
			// $scope.prompt = {};
			$scope.prompt = prompt;<commit_msg>null checking and correct call of static method isarray<commit_after>(function () {
	'use strict';
	
	/**
	 * @ngdoc overview
	 * @name app
	 * @description
	 * # The...
	 */
	angular.module('app')
		.controller('RecieverController', RecieverController);

	RecieverController.$inject = ['$scope', '$modal', '$log', 'ThoughtSocket',
		'UserService', '$location', '$routeParams', '$rootScope', '$timeout',
		'toastr', '$animate', 'LoggerService'];
	function RecieverController($scope, $modal, $log, ThoughtSocket,
		UserService, $location, $routeParams, $rootScope, $timeout, 
	 toastr, $animate, Logger) {

		(function initController() {
			$scope.participantThoughts = [];
			$scope.prompt = {};
			$scope.numSubmitters = 0;
			$scope.numConnected = 0;
			$scope.dataLoading = true;
			$scope.ngmSettings = {
        	    closeEl: '.close',
        	    overlay: {
        	        templateUrl: 'facilitator/thoughtOverlay.html'
        	    }
        	};

			ThoughtSocket.emit('facilitator-join', {
				groupId: $routeParams.groupId,
				userId: UserService.user.id
			});

			$scope.BG_COLORS = {
				// 1: 'red',
				// 2: 'orange',
			};

			ThoughtSocket.on('group-colors', function (colors) {
        console.log('group-colors', colors);
        colors.forEach(function (color) {
        	$scope.BG_COLORS[color.id] = color;
        });
      });

		})();

		// TEMP METHOD: Test thoughts - adds some thoughts automatically to the
		// teacher view for ui testing.
		$scope.testThoughts = function () {
			console.log("got testThoughts cmd");
			for (var i = 0; i < 16; i++) {
				Logger.createEvent({
					data: 'content: ' + i + " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
				});
				$scope.participantThoughts.push({
					localIdx: $scope.participantThoughts.length,
					content: i + " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
				});
			}
		};

		$scope.animatedBounce = function (elemId) {
			$animate.addClass($(elemId), 'animated bounce')
				.then(function () {
					$timeout(function () {
						$animate.removeClass($('#numConnected'),'animated bounce');
					}, 1000);
				});
		};

		$scope.$watch('participantThoughts.length', function (nv, ov) {
			if (nv !== ov) {
				$scope.animatedBounce('#numThoughts');
			}
		});

		$scope.$watch('numSubmitters', function (nv, ov) {
			if (nv !== ov) {
				$scope.animatedBounce('#numSubmitters');
			}
		});

		$scope.$watch('numConnected', function (nv, ov) {
			if (nv !== ov) {
				$scope.animatedBounce('#numConnected');
			}
		});

		$scope.thoughtMoved = function (idx) {
			$scope.participantThoughts.splice(idx, 1);
			$scope.updateLocalIdx();
		};

		ThoughtSocket.on('facilitator-prompt', function (data) {
			console.log('facilitator-prompt', data);
			$scope.prompt = data;
			$scope.participantThoughts = [];
			toastr.success('', 'New Prompt Created');
		});

		ThoughtSocket.on('participant-join', function () {
			console.log('participant-join');
			$scope.numConnected++;
		});

		ThoughtSocket.on('participant-leave', function () {
			console.log('participant-leave');
			$scope.numConnected--;
		});

		ThoughtSocket.on('sessionsyncres', function (data) {
			console.log('Recieved session sync response:', data);
			// $scope.participantThoughts = data.prompt.get('thoughts'); //TODO: at somepoint sync should send us the existing thoughts if we're late joining
			$scope.prompt = data.prompt;
			$scope.sessionId = data.sessionId;
			if (data && data.hasOwnProperty('prompt') && data.prompt.hasOwnProperty('thoughts') && data.prompt.thoughts && Array.isArray(data.prompt.thoughts)) {
				$scope.participantThoughts = data.prompt.thoughts;
			}
			// $scope.numThoughts = data.prompt.thoughts.length();
			// $scope.numSubmitters = ?
		});

		$scope.newSession = function () {
			$scope.participantThoughts = [];
			//$scope.numThoughts = 0;
			$scope.numSubmitters = 0;
			ThoughtSocket.emit('session-sync-req', {
				userId: UserService.user.id,
				groupId: $routeParams.groupId,
				sessionId: $scope.sessionId
			});
			Logger.createEvent({
				data: 'new session for group: ' + $routeParams.groupId,
				type: 'newSession'
			});
			toastr.success('', 'Started New Session');
		};

		ThoughtSocket.on('new-session-prompt', function (prompt) {
			console.log("Got data in new-session-prompt", prompt);
			// $scope.prompt = {};
			$scope.prompt = prompt;
{'fraction_non_alphanumeric': 0.1468114241001565, 'fraction_numerical': 0.0027386541471048514, 'mean_word_length': 3.5444444444444443, 'pattern_counts': {'":': 0, '<': 5, '<?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': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2123175', 'n_tokens_mistral': 3969, 'n_tokens_neox': 3315, 'n_words': 775}