<commit_before>"use strict";

let {onOpen,onMessage,onClose,listen,send} = require("../../lib/socketConn"),
    {addMethod} = require("genfun"),
    {clone, init} = require("../../lib/proto"),
    {extend, last} = require("lodash"),
    can = require("../../shims/can");

/**
 * Chatlog Model
 */
let Chatlog = clone();

/*
 * Init
 */
addMethod(init, [Chatlog], function(log, conn, ns) {
  log.conn = conn;
  log.namespace = ns;
  listen(conn, log, ns);
  initModelList(log);
});

function initModelList(log) {
  log.entryGroups = new EntryGroup.List([]);
}

/*
 * Event handling
 */
addMethod(onOpen, [Chatlog], function(log) {
  addEntry(log, {entryType: "system", content: "Connected"});
});

addMethod(onMessage, [Chatlog], function(log, data) {
  addEntry(log, data);
});

addMethod(onClose, [Chatlog], function(log) {
  addEntry(log, {entryType: "system", content: "Disconnected..."});
});

function submitEntry(log, type, opts) {
  let msg = extend({_sent: (new Date()).getTime()},
                   {entryType: type},
                   opts || {});
  send(log.conn, log.namespace, msg);
}

/*
 * Entries
 */
function addEntry(log, entryInfo) {
  let lastMsgGroup = last(log.entryGroups),
      entry = new Entry(extend({_received: (new Date()).getTime()}, entryInfo));
  if (lastMsgGroup &&
      lastMsgGroup.firstEntry.entryType === entryInfo.entryType &&
      lastMsgGroup.firstEntry.groupTag === entryInfo.groupTag) {
    lastMsgGroup.entries.push(entry);
  } else {
    log.entryGroups.push(
      new EntryGroup({firstEntry: entry, entries: new Entry.List([entry])}));
  }
}

/*
 * Canjs Model
 */
var EntryGroup = can.Model.extend(),
    Entry = can.Model.extend();

module.exports.Chatlog = Chatlog;
module.exports.submitEntry = submitEntry;<commit_msg>Go ahead and export it<commit_after>"use strict";

let {onOpen,onMessage,onClose,listen,send} = require("../../lib/socketConn"),
    {addMethod} = require("genfun"),
    {clone, init} = require("../../lib/proto"),
    {extend, last} = require("lodash"),
    can = require("../../shims/can");

/**
 * Chatlog Model
 */
let Chatlog = clone();

/*
 * Init
 */
addMethod(init, [Chatlog], function(log, conn, ns) {
  log.conn = conn;
  log.namespace = ns;
  listen(conn, log, ns);
  initModelList(log);
});

function initModelList(log) {
  log.entryGroups = new EntryGroup.List([]);
}

/*
 * Event handling
 */
addMethod(onOpen, [Chatlog], function(log) {
  addEntry(log, {entryType: "system", content: "Connected"});
});

addMethod(onMessage, [Chatlog], function(log, data) {
  addEntry(log, data);
});

addMethod(onClose, [Chatlog], function(log) {
  addEntry(log, {entryType: "system", content: "Disconnected..."});
});

function submitEntry(log, type, opts) {
  let msg = extend({_sent: (new Date()).getTime()},
                   {entryType: type},
                   opts || {});
  send(log.conn, log.namespace, msg);
}

/*
 * Entries
 */
function addEntry(log, entryInfo) {
  let lastMsgGroup = last(log.entryGroups),
      entry = new Entry(extend({_received: (new Date()).getTime()}, entryInfo));
  if (lastMsgGroup &&
      lastMsgGroup.firstEntry.entryType === entryInfo.entryType &&
      lastMsgGroup.firstEntry.groupTag === entryInfo.groupTag) {
    lastMsgGroup.entries.push(entry);
  } else {
    log.entryGroups.push(
      new EntryGroup({firstEntry: entry, entries: new Entry.List([entry])}));
  }
}

/*
 * Canjs Model
 */
var EntryGroup = can.Model.extend(),
    Entry = can.Model.extend();

module.exports.Chatlog = Chatlog;
module.exports.submitEntry = submitEntry;
module.exports.addEntry = addEntry;
{'fraction_non_alphanumeric': 0.1871345029239766, 'fraction_numerical': 0.0, 'mean_word_length': 3.763925729442971, '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': '2872747', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1178, 'n_words': 239}