2014-09-13 21:29:45 +00:00
|
|
|
var _ = require("lodash");
|
|
|
|
|
|
|
|
module.exports = Chan;
|
|
|
|
|
|
|
|
Chan.Type = {
|
|
|
|
CHANNEL: "channel",
|
|
|
|
LOBBY: "lobby",
|
|
|
|
QUERY: "query"
|
|
|
|
};
|
|
|
|
|
|
|
|
var id = 0;
|
|
|
|
|
|
|
|
function Chan(attr) {
|
|
|
|
_.merge(this, _.extend({
|
|
|
|
id: id++,
|
|
|
|
messages: [],
|
|
|
|
name: "",
|
|
|
|
type: Chan.Type.CHANNEL,
|
2014-09-21 16:46:43 +00:00
|
|
|
unread: 5,
|
2014-09-13 21:29:45 +00:00
|
|
|
users: []
|
|
|
|
}, attr));
|
|
|
|
}
|
|
|
|
|
|
|
|
Chan.prototype.sortUsers = function() {
|
|
|
|
this.users = _.sortBy(
|
|
|
|
this.users,
|
|
|
|
function(u) { return u.name.toLowerCase(); }
|
|
|
|
);
|
|
|
|
var modes = [
|
|
|
|
"~",
|
2014-09-14 00:11:19 +00:00
|
|
|
"&",
|
2014-09-13 21:29:45 +00:00
|
|
|
"@",
|
2014-09-14 00:11:19 +00:00
|
|
|
"%",
|
2014-09-13 21:29:45 +00:00
|
|
|
"+",
|
|
|
|
].reverse();
|
|
|
|
modes.forEach(function(mode) {
|
|
|
|
this.users = _.remove(
|
|
|
|
this.users,
|
|
|
|
function(u) { return u.mode == mode; }
|
|
|
|
).concat(this.users);
|
|
|
|
}, this);
|
|
|
|
};
|
|
|
|
|
|
|
|
Chan.prototype.toJSON = function() {
|
|
|
|
var clone = _.clone(this);
|
|
|
|
clone.messages = clone.messages.slice(-100);
|
|
|
|
return clone;
|
|
|
|
};
|