thelounge/lib/models/chan.js

28 lines
511 B
JavaScript
Raw Normal View History

var _ = require("lodash");
module.exports = Chan;
function Chan(attr) {
_.merge(this, _.extend({
id: global.id = ++global.id || 1,
name: "",
type: "",
messages: [],
users: [],
}, attr));
};
2014-04-29 13:01:30 +00:00
2014-04-30 15:14:22 +00:00
Chan.prototype.sortUsers = function() {
this.users = _.sortBy(
this.users,
function(u) { return u.name.toLowerCase(); }
);
var modes = ["+", "@"];
modes.forEach(function(mode) {
this.users = _.remove(
2014-04-29 13:01:30 +00:00
this.users,
2014-04-30 15:14:22 +00:00
function(u) { return u.mode == mode; }
).concat(this.users);
}, this);
2014-04-29 13:01:30 +00:00
};