Shuo/lib/models/chan.js

41 lines
657 B
JavaScript
Raw Normal View History

2014-06-26 23:05:47 +00:00
var _ = require("lodash");
module.exports = Chan;
Chan.Type = {
CHANNEL: "channel",
LOBBY: "lobby",
QUERY: "query"
};
2014-06-29 01:07:38 +00:00
var id = 0;
2014-06-26 23:05:47 +00:00
function Chan(attr) {
_.merge(this, _.extend({
2014-06-29 01:07:38 +00:00
id: id++,
2014-06-26 23:05:47 +00:00
messages: [],
2014-07-08 20:50:41 +00:00
name: "",
type: Chan.Type.CHANNEL,
2014-06-26 23:05:47 +00:00
users: []
2014-06-30 01:20:54 +00:00
}, attr));
2014-06-26 23:05:47 +00:00
}
2014-06-29 19:41:02 +00:00
Chan.prototype.sortUsers = function() {
2014-07-07 21:52:45 +00: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 19:41:02 +00:00
};