<commit_before>goog.provide('napster.chat');


var chat	= new function () {




/**
* @namespace Chat
*/
var self	= this;




/**
* @function
* @property {void} Initialises this namespace
*/
var init;

/**
* @function
* @property {void} Adds user to group
* @param {string} groupid
*/
var addToGroup;

/**
* @function
* @property {void} Creates new group
* @param {string} opt_name
*/
var createGroup;

/**
* @function
* @property {void} Removes user from group
* @param {string} groupid
*/
var removeFromGroup;

/**
* @function
* @property {void} Switches active group to specified
* @param {string} groupid
*/
var switchToGroup;

/**
* @function
* @property {void} Sends message
* @param {string} message
* @param {string} opt_groupid
*/
var sendMessage;




self.init	= function () {
	/* For now, adding/switching all users to default group upon login */
	self.switchToGroup('0');
};

self.addToGroup	= function (groupid) {
	datastore.group(groupid).member(authentication.userid).set(authentication.userid);
	datastore.user().group(groupid).set(groupid);
	ui.update();
};

self.createGroup	= function (opt_name) {
	var group	= datastore.groupRoot.push({
		name: opt_name || 'Chat {0}'.assign({0: Date.now().toString().slice(-3)})
	});

	self.addToGroup(group.name());
};

self.removeFromGroup	= function (groupid) {
	datastore.group(groupid).member(authentication.userid).set(null);
	datastore.user().group(groupid).set(null);
	ui.update();
};

self.switchToGroup	= function (groupid) {
	self.addToGroup(groupid);

	var wait		= new goog.async.ConditionalDelay(function () { return datastore.data.group[groupid]; });
	wait.onSuccess	= function () {
		datastore.data.activeGroup	= datastore.data.group[groupid];
		ui.update();
	};
	wait.start(1000, 60000);
};

self.sendMessage	= function (message, opt_groupid) {
	datastore.group(opt_groupid).messages.push({author: authentication.userid, created: Date.now(), text: message});
	ui.update();
};<commit_msg>minor optimisatio<commit_after>goog.provide('napster.chat');


var chat	= new function () {




/**
* @namespace Chat
*/
var self	= this;




/**
* @function
* @property {void} Initialises this namespace
*/
var init;

/**
* @function
* @property {void} Adds user to group
* @param {string} groupid
*/
var addToGroup;

/**
* @function
* @property {void} Creates new group
* @param {string} opt_name
*/
var createGroup;

/**
* @function
* @property {void} Removes user from group
* @param {string} groupid
*/
var removeFromGroup;

/**
* @function
* @property {void} Switches active group to specified
* @param {string} groupid
*/
var switchToGroup;

/**
* @function
* @property {void} Sends message
* @param {string} message
* @param {string} opt_groupid
*/
var sendMessage;




self.init	= function () {
	/* For now, adding/switching all users to default group upon login */
	self.switchToGroup('0');
};

self.addToGroup	= function (groupid) {
	datastore.group(groupid).member(authentication.userid).set(authentication.userid);
	datastore.user().group(groupid).set(groupid);
	ui.update();
};

self.createGroup	= function (opt_name) {
	var group	= datastore.groupRoot.push({
		name: opt_name || 'Chat {0}'.assign({0: Date.now().toString().slice(-3)})
	});

	self.addToGroup(group.name());
};

self.removeFromGroup	= function (groupid) {
	datastore.group(groupid).member(authentication.userid).set(null);
	datastore.user().group(groupid).set(null);
	ui.update();
};

self.switchToGroup	= function (groupid) {
	self.addToGroup(groupid);

	var wait		= new goog.async.ConditionalDelay(function () { return datastore.data.group[groupid]; });
	wait.onSuccess	= function () {
		datastore.data.activeGroup	= datastore.data.group[groupid];
		ui.update();
	};

	if (datastore.data.group[groupid]) {
		wait.onSuccess();
	}
	else {
		wait.start(1000, 60000);
	}
};

self.sendMessage	= function (message, opt_groupid) {
	datastore.group(opt_groupid).messages.push({author: authentication.userid, created: Date.now(), text: message});
	ui.update();
};
{'fraction_non_alphanumeric': 0.1683366733466934, 'fraction_numerical': 0.006513026052104208, 'mean_word_length': 4.795355587808418, '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': '6829978', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1384, 'n_words': 293}