<commit_before>'use strict';

angular.module('chatspace.controllers', []).
  controller('AppCtrl', function ($scope, authenticate, $rootScope, $http, $location, $routeParams, user) {
    user.call();
    $rootScope.friendPredicate = '-username';
    $rootScope.recipients = {};
    $rootScope.latestMessage;

    localForage.getItem('latestMessageKey', function (key) {
      $rootScope.latestMessage = key;
    });

    socket.on('friend', function (data) {
      $rootScope.$apply(function () {
        $rootScope.friends[data.friend.userHash] = {
          username: data.friend.username,
          avatar: data.friend.avatar,
          userHash: data.friend.userHash,
          senderUserHash: data.friend.senderUserHash
        };
      });
    });

    socket.on('notification', function (data) {
      $rootScope.$apply(function () {
        console.log(data)
        if (data && $rootScope.notifications.indexOf(data) === -1) {
          $rootScope.notifications.push(data);
          $rootScope.latestMessage = data;
        }
      });
    });

    socket.on('message', function (data) {
      $rootScope.$apply(function () {
        var senderKey = data.value.reply || data.value.senderKey;

        if ($location.path() === '/dashboard' || $routeParams.senderKey === senderKey) {
          $rootScope.messages.unshift(data);
          console.log(data)
          // also save message to local cache
          localForage.setItem('messages', $rootScope.messages);
          localForage.setItem('latestMessageKey', data.key); // last one at the top is the latest
          $rootScope.latestMessage = data.key;

          $rootScope.recipients = {};

          if ($routeParams.senderKey === senderKey) {
            data.value.recipients.forEach(function (userHash) {
              $rootScope.recipients[userHash] = userHash;
            });

            $rootScope.reply = senderKey;
          }
        }
      });
    });

    socket.on('blocked', function (data) {
      $rootScope.$apply(function () {
        $rootScope.blocked[data.user.userHash] = {
          username: data.user.username,
          avatar: data.user.avatar,
          userHash: data.user.userHash
        };
      });
    });

    $rootScope.getDate = function (timestamp) {
      return moment.unix(Math.round(timestamp / 1000)).fromNow();
    };

    $rootScope.goToDashboard = function () {
      $location.path('/dashboard');
    };

    $rootScope.toggleSettings = function () {
      if ($rootScope.settings) {
        $rootScope.settings = false;
      } else {
        $rootScope.settings = true;
      }
    };

    $rootScope.newMessage = function () {
        $rootScope.settings = false;
    };

    var email = localStorage.getItem('personaEmail');

    if (email) {
      $rootScope.isAuthenticated = true;
    }

    $rootScope.logout = function () {
      authenticate.logout();
    }
  }).
  controller('HomeCtrl', function ($scope, $rootScope, $location, authenticate) {
    $scope.login = function () {
      authenticate.login();
      $rootScope.toggleSettings();
    };
  }).
  controller('MessageCtrl', function ($scope, $rootScope, $http, $routeParams, $location, cameraHelper, api) {
    api.call();

    $rootScope.messages = [];

    var resetForm = function () {
      if (!$routeParams.senderKey) {<commit_msg>don't clear messages during load<commit_after>'use strict';

angular.module('chatspace.controllers', []).
  controller('AppCtrl', function ($scope, authenticate, $rootScope, $http, $location, $routeParams, user) {
    user.call();
    $rootScope.friendPredicate = '-username';
    $rootScope.recipients = {};
    $rootScope.latestMessage;

    localForage.getItem('latestMessageKey', function (key) {
      $rootScope.latestMessage = key;
    });

    socket.on('friend', function (data) {
      $rootScope.$apply(function () {
        $rootScope.friends[data.friend.userHash] = {
          username: data.friend.username,
          avatar: data.friend.avatar,
          userHash: data.friend.userHash,
          senderUserHash: data.friend.senderUserHash
        };
      });
    });

    socket.on('notification', function (data) {
      $rootScope.$apply(function () {
        if (data && $rootScope.notifications.indexOf(data) === -1) {
          $rootScope.notifications.push(data);
          $rootScope.latestMessage = data;
        }
      });
    });

    socket.on('message', function (data) {
      $rootScope.$apply(function () {
        var senderKey = data.value.reply || data.value.senderKey;

        if ($location.path() === '/dashboard' || $routeParams.senderKey === senderKey) {
          $rootScope.messages.unshift(data);

          // also save message to local cache
          localForage.setItem('messages', $rootScope.messages);
          localForage.setItem('latestMessageKey', data.key); // last one at the top is the latest
          $rootScope.latestMessage = data.key;

          $rootScope.recipients = {};

          if ($routeParams.senderKey === senderKey) {
            data.value.recipients.forEach(function (userHash) {
              $rootScope.recipients[userHash] = userHash;
            });

            $rootScope.reply = senderKey;
          }
        }
      });
    });

    socket.on('blocked', function (data) {
      $rootScope.$apply(function () {
        $rootScope.blocked[data.user.userHash] = {
          username: data.user.username,
          avatar: data.user.avatar,
          userHash: data.user.userHash
        };
      });
    });

    $rootScope.getDate = function (timestamp) {
      return moment.unix(Math.round(timestamp / 1000)).fromNow();
    };

    $rootScope.goToDashboard = function () {
      $location.path('/dashboard');
    };

    $rootScope.toggleSettings = function () {
      if ($rootScope.settings) {
        $rootScope.settings = false;
      } else {
        $rootScope.settings = true;
      }
    };

    $rootScope.newMessage = function () {
        $rootScope.settings = false;
    };

    var email = localStorage.getItem('personaEmail');

    if (email) {
      $rootScope.isAuthenticated = true;
    }

    $rootScope.logout = function () {
      authenticate.logout();
    }
  }).
  controller('HomeCtrl', function ($scope, $rootScope, $location, authenticate) {
    $scope.login = function () {
      authenticate.login();
      $rootScope.toggleSettings();
    };
  }).
  controller('MessageCtrl', function ($scope, $rootScope, $http, $routeParams, $location, cameraHelper, api) {
    api.call();

    var resetForm = function () {
      if (!$routeParams.senderKey) {
{'fraction_non_alphanumeric': 0.1492786636294609, 'fraction_numerical': 0.0015186028853454822, 'mean_word_length': 2.4535920293654954, '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': '2470657', 'n_tokens_mistral': 1950, 'n_tokens_neox': 1898, 'n_words': 323}