<commit_before>angular.module('app.controllers', [])
  .controller('LandingController', ['$scope', 'socket', 'Event', '$state', '$stateParams',
    function ($scope, socket, Event, $state, $stateParams) {
      console.log('in landing controller');
      $scope.joinError = $stateParams.roomError;
      //function called when join button clicked
      $scope.join = function (event) {
        $state.go('event', {event: event});
      };
      //directs user to the create event page
      $scope.create = function (event) {
        socket.emit('create', event);
        socket.on('createable', function (createable) {
          if (createable) {
          //set the name of the event.
            Event.event = event;
            Event.creator = socket.id();
            //redirect  to the event
            $state.go('event', {event: event});
          } else {
            $scope.joinError = false;
            $scope.createError = true;
          }
        });
      };
    }
  ])
  .controller('EventController', ['$window', '$scope', '$state', 'socket', 'Event', '$rootScope', '$stateParams',
    function ($window, $scope, $state, socket, Event, $rootScope, $stateParams) {
      console.log('in event controller');

      //this is the array that gets ng-repeated in the view
      $scope.songs = [];

      // this variable will let us hide the player from event insiders other than
      // the creator
      $scope.isCreator = socket.id() === Event.creator;

      // to keep track of which song is up
      $scope.songIndex = 0;

      //link to the search view
      $scope.search = function () {
        $state.go('event.search');
      };

      $scope.roomInvite = $state.href($state.current.name, $state.params, {
        absolute: true
      });

      $scope.shareEvent = function () {
        new Clipboard('.share');
      };

      $scope.playNext = function () {
        var topSong = $scope.sortedSongs[0];
        player.loadVideoById(topSong.id);
        socket.emit('removeSong', topSong.id);
      };

      $scope.upVote = function () {
        socket.emit('upVote', this.song.id);
      };

      socket.on('voted', function (song) {
        $scope.songs.forEach(function (item) {
          if (item.id === song.id) {
            item.votes = song.votes;
            item.liked = true;
          }
        });
        // multiple socket calls means this is called too often. 
        //for efficiency it should be throttled.
        $scope.sortedSongs = $scope.songs.sort(function (a,b) {
          return b.votes - a.votes;
        });
      });

      console.log('url', $stateParams.event);
      socket.emit('join', $stateParams.event);

      //let the server know that insider has arrived in the room.
      socket.on('success', function (success) {
        if (success) {
          socket.emit('joined');
        } else {
          $rootScope.destroyed = true;
          player.destroy();
          $state.go('landing', {roomError: true});
        }
      });<commit_msg>Fix like button accross network.<commit_after>angular.module('app.controllers', [])
  .controller('LandingController', ['$scope', 'socket', 'Event', '$state', '$stateParams',
    function ($scope, socket, Event, $state, $stateParams) {
      console.log('in landing controller');
      $scope.joinError = $stateParams.roomError;
      //function called when join button clicked
      $scope.join = function (event) {
        $state.go('event', {event: event});
      };
      //directs user to the create event page
      $scope.create = function (event) {
        socket.emit('create', event);
        socket.on('createable', function (createable) {
          if (createable) {
          //set the name of the event.
            Event.event = event;
            Event.creator = socket.id();
            //redirect  to the event
            $state.go('event', {event: event});
          } else {
            $scope.joinError = false;
            $scope.createError = true;
          }
        });
      };
    }
  ])
  .controller('EventController', ['$window', '$scope', '$state', 'socket', 'Event', '$rootScope', '$stateParams',
    function ($window, $scope, $state, socket, Event, $rootScope, $stateParams) {
      console.log('in event controller');

      //this is the array that gets ng-repeated in the view
      $scope.songs = [];

      // this variable will let us hide the player from event insiders other than
      // the creator
      $scope.isCreator = socket.id() === Event.creator;

      // to keep track of which song is up
      $scope.songIndex = 0;

      //link to the search view
      $scope.search = function () {
        $state.go('event.search');
      };

      $scope.roomInvite = $state.href($state.current.name, $state.params, {
        absolute: true
      });

      $scope.shareEvent = function () {
        new Clipboard('.share');
      };

      $scope.playNext = function () {
        var topSong = $scope.sortedSongs[0];
        player.loadVideoById(topSong.id);
        socket.emit('removeSong', topSong.id);
      };

      $scope.upVote = function () {
        socket.emit('upVote', this.song.id);
        console.log(this.song.liked);
        this.song.liked = true;
      };

      socket.on('voted', function (song) {
        $scope.songs.forEach(function (item) {
          if (item.id === song.id) {
            item.votes = song.votes;
          }
        });
        // multiple socket calls means this is called too often. 
        //for efficiency it should be throttled.
        $scope.sortedSongs = $scope.songs.sort(function (a,b) {
          return b.votes - a.votes;
        });
      });

      console.log('url', $stateParams.event);
      socket.emit('join', $stateParams.event);

      //let the server know that insider has arrived in the room.
      socket.on('success', function (success) {
        if (success) {
          socket.emit('joined');
        } else {
          $rootScope.destroyed = true;
          player.destroy();
          $state.go('landing', {roomError: true});
        }
      });
{'fraction_non_alphanumeric': 0.14911125740618827, 'fraction_numerical': 0.0006583278472679394, 'mean_word_length': 2.0645486636409482, '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': '7523984', 'n_tokens_mistral': 1781, 'n_tokens_neox': 1727, 'n_words': 439}