var wompt = require("./includes");

function MetaUser(doc){
	var me = this;
	this.clients = new wompt.ClientPool();
	this.doc = doc;
	this.visible = !!doc;
	this.readonly = !doc;
	this.touch();
	
	this.clients.on('added', function(client){
		me.clients.broadcast({
			action: 'new_client',
			channel: client.meta_data.channel.name
		},client);
	});	
};


MetaUser.prototype.id = function(){
	return this.doc ? this.doc._id.toString() : null;
}

MetaUser.prototype.touch = function(){
	this.touched = new Date();
}

MetaUser.prototype.authenticated = function(){
	return !!this.doc;
}

MetaUser.prototype.new_session = function(session){
	this.clients.broadcast({
		action: 'new_session'		
	});
}

MetaUser.prototype.end_session = function(session){
	this.clients.broadcast({
		action: 'end_session'
	});
	this.clients.each(function(client, index){
		if(client.meta_data && client.meta_data.token == session.token)
			client._onDisconnect();
	});
}

module.exports = MetaUser

var wompt = require("./includes");

function MetaUser(doc){
	var me = this;
	this.clients = new wompt.ClientPool();
	this.doc = doc;
	this.visible = !!doc;
	this.readonly = !doc;
	this.touch();
	
	this.clients.on('added', function(client){
		me.clients.broadcast({
			action: 'new_client',
			channel: client.meta_data.channel.name
		},client);
	});	
};


MetaUser.prototype.id = function(){
	return this.doc ? this.doc._id.toJSON() : null;
}

MetaUser.prototype.touch = function(){
	this.touched = new Date();
}

MetaUser.prototype.authenticated = function(){
	return !!this.doc;
}

MetaUser.prototype.new_session = function(session){
	this.clients.broadcast({
		action: 'new_session'		
	});
}

MetaUser.prototype.end_session = function(session){
	this.clients.broadcast({
		action: 'end_session'
	});
	this.clients.each(function(client, index){
		if(client.meta_data && client.meta_data.token == session.token)
			client._onDisconnect();
	});
}

module.exports = MetaUser

Change User ID to use the JSON (hex) representation throughout the site
Change User ID to use the JSON (hex) representation throughout the site
