mirror of
https://github.com/thelounge/thelounge
synced 2024-12-23 19:03:08 +00:00
40 lines
657 B
JavaScript
40 lines
657 B
JavaScript
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,
|
|
users: []
|
|
}, attr));
|
|
}
|
|
|
|
Chan.prototype.sortUsers = function() {
|
|
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);
|
|
};
|