thelounge/src/models/chan.js

47 lines
793 B
JavaScript
Raw Normal View History

2014-06-27 01:05:47 +02:00
var _ = require("lodash");
module.exports = Chan;
Chan.Type = {
CHANNEL: "channel",
LOBBY: "lobby",
QUERY: "query"
};
2014-06-29 03:07:38 +02:00
var id = 0;
2014-06-27 01:05:47 +02:00
function Chan(attr) {
_.merge(this, _.extend({
2014-06-29 03:07:38 +02:00
id: id++,
2014-06-27 01:05:47 +02:00
messages: [],
2014-07-08 22:50:41 +02:00
name: "",
type: Chan.Type.CHANNEL,
2014-06-27 01:05:47 +02:00
users: []
2014-06-30 03:20:54 +02:00
}, attr));
2014-06-27 01:05:47 +02:00
}
2014-06-29 21:41:02 +02:00
Chan.prototype.sortUsers = function() {
2014-07-07 23:52:45 +02:00
this.users = _.sortBy(
this.users,
function(u) { return u.name.toLowerCase(); }
);
var modes = [
"~",
"%",
"@",
"+",
].reverse();
modes.forEach(function(mode) {
this.users = _.remove(
this.users,
function(u) { return u.mode == mode; }
).concat(this.users);
}, this);
2014-06-29 21:41:02 +02:00
};
2014-07-20 21:49:44 +02:00
Chan.prototype.toJSON = function() {
var clone = _.clone(this);
clone.messages = clone.messages.slice(-100);
return clone;
};