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: "",
|
2014-10-10 20:05:25 +00:00
|
|
|
topic: "",
|
2014-09-13 21:29:45 +00:00
|
|
|
type: Chan.Type.CHANNEL,
|
2014-09-21 16:48:01 +00:00
|
|
|
unread: 0,
|
2016-03-13 16:05:05 +00:00
|
|
|
highlight: false,
|
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(); }
|
|
|
|
);
|
2016-03-14 05:44:03 +00:00
|
|
|
|
|
|
|
["+", "%", "@", "&", "~"].forEach(function(mode) {
|
2014-09-13 21:29:45 +00:00
|
|
|
this.users = _.remove(
|
|
|
|
this.users,
|
2015-09-30 22:39:57 +00:00
|
|
|
function(u) { return u.mode === mode; }
|
2014-09-13 21:29:45 +00:00
|
|
|
).concat(this.users);
|
|
|
|
}, this);
|
|
|
|
};
|
|
|
|
|
2014-10-04 12:31:45 +00:00
|
|
|
Chan.prototype.getMode = function(name) {
|
|
|
|
var user = _.find(this.users, {name: name});
|
|
|
|
if (user) {
|
|
|
|
return user.mode;
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-13 21:29:45 +00:00
|
|
|
Chan.prototype.toJSON = function() {
|
|
|
|
var clone = _.clone(this);
|
|
|
|
clone.messages = clone.messages.slice(-100);
|
|
|
|
return clone;
|
|
|
|
};
|