<commit_before>'use strict';

/**
 * @ngdoc function
 * @name Pear2Pear.service:Pear
 * @description
 * # Pear service
 * Provides controllers with a data model for pear to pear app
 * It serves as an abstraction between Pear data and backend (SwellRT)
 */

angular.module('Pear2Pear')
  .factory('pear', ['$rootScope', 'swellRT', '$q', function($rootScope, swellRT, $q) {

    var model = {
      model : swellRT.copy,
    };

    var projects = {
      all: function() {
        return model.model;
      },
      find: function(id) {
        return model.model[id];
      },
      create: function(callback) {
        var p = {
          id: Math.random().toString(36).substr(2, 5),
          title: '',
          chat: [],
          pad: ''
        };

        swellRT.copy[p.id] = p;
        callback(p);
      }
    };

    var addChatMessage = function(projectId, message, who) {
      model.model[projectId].chat.push({
        text: message,
        // TODO change when ready
        standpoint: 'mine',
        who: who,
        time: ''+ new Date().getTime()
      });
    }

    var def = $q.defer();

    swellRT.open(window.swellrtConfig.chatpadWaveId).then(
      function() {
        model.model = swellRT.copy;
        def.resolve(swellRT.copy);
      });

    var ret = {
      projects: projects,
      addChatMessage: addChatMessage, 
      onLoad: function(f){
        def.promise.then(f);
      }
    }
    return ret;
  }]);<commit_msg>Save message time in JSON format<commit_after>'use strict';

/**
 * @ngdoc function
 * @name Pear2Pear.service:Pear
 * @description
 * # Pear service
 * Provides controllers with a data model for pear to pear app
 * It serves as an abstraction between Pear data and backend (SwellRT)
 */

angular.module('Pear2Pear')
  .factory('pear', ['$rootScope', 'swellRT', '$q', function($rootScope, swellRT, $q) {

    var model = {
      model : swellRT.copy,
    };

    var projects = {
      all: function() {
        return model.model;
      },
      find: function(id) {
        return model.model[id];
      },
      create: function(callback) {
        var p = {
          id: Math.random().toString(36).substr(2, 5),
          title: '',
          chat: [],
          pad: ''
        };

        swellRT.copy[p.id] = p;
        callback(p);
      }
    };

    var addChatMessage = function(projectId, message, who) {
      model.model[projectId].chat.push({
        text: message,
        // TODO change when ready
        standpoint: 'mine',
        who: who,
        time: (new Date()).toJSON()
      });
    }

    var def = $q.defer();

    swellRT.open(window.swellrtConfig.chatpadWaveId).then(
      function() {
        model.model = swellRT.copy;
        def.resolve(swellRT.copy);
      });

    var ret = {
      projects: projects,
      addChatMessage: addChatMessage, 
      onLoad: function(f){
        def.promise.then(f);
      }
    }
    return ret;
  }]);
{'fraction_non_alphanumeric': 0.14280845262440353, 'fraction_numerical': 0.00408997955010225, 'mean_word_length': 2.01025641025641, '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': '3590765', 'n_tokens_mistral': 949, 'n_tokens_neox': 906, 'n_words': 213}