<commit_before>'use strict';

angular.module('chatApp', [])

.controller('ChatCtrl', function($scope, $http) {

   $scope.chatChannel = "chatApp";
   $scope.messageLimit = 50;
   $scope.defaultUsername = "Guest";

   $scope.currentConnectionStatus = 0;
   $scope.errorMessage;
   $scope.loggedIn = false;

   $scope.chatLogs = function() {
      PUBNUB.history( {
         channel: $scope.chatChannel,
         limit: $scope.messageLimit
      }, function(messages) {
         $scope.$apply(function(){
            $scope.chatMessages = messages;          
         }); 
      });
   };

   $scope.postMessage = function() {
      PUBNUB.publish({
         channel : $scope.chatChannel,
         message : $scope.message
      });

      $scope.message.text = "";
   };

   PUBNUB.subscribe({
      channel: $scope.chatChannel,
      restore: false,

      callback: function(message) { 
      //update messages with the new message
         $scope.$apply(function(){
            $scope.chatMessages.unshift(message);          
         }); 
      },<commit_msg>Ensure user is logged in and enters a message before posting the message<commit_after>'use strict';

angular.module('chatApp', [])

.controller('ChatCtrl', function($scope, $http) {

   $scope.chatChannel = "chatApp";
   $scope.messageLimit = 50;
   $scope.defaultUsername = "Guest";

   $scope.currentConnectionStatus = 0;
   $scope.errorMessage;
   $scope.loggedIn = false;

   $scope.chatLogs = function() {
      PUBNUB.history( {
         channel: $scope.chatChannel,
         limit: $scope.messageLimit
      }, function(messages) {
         $scope.$apply(function(){
            $scope.chatMessages = messages;          
         }); 
      });
   };

   $scope.postMessage = function() {
      if (!$scope.loggedIn) {
        $scope.errorMessage = "You must login first.";
        return;
      }

      if (!$scope.message.text) {
        $scope.errorMessage = "You must enter a message.";
        return;
      }

      PUBNUB.publish({
         channel : $scope.chatChannel,
         message : $scope.message
      });

      $scope.message.text = "";
   };

   PUBNUB.subscribe({
      channel: $scope.chatChannel,
      restore: false,

      callback: function(message) { 
      //update messages with the new message
         $scope.$apply(function(){
            $scope.chatMessages.unshift(message);          
         }); 
      },
{'fraction_non_alphanumeric': 0.13977602654500207, 'fraction_numerical': 0.002488593944421402, 'mean_word_length': 2.1612057667103537, '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': '3766206', 'n_tokens_mistral': 719, 'n_tokens_neox': 691, 'n_words': 131}