Sort user list within a single pass, use server provided user modes
This commit is contained in:
parent
516ccd965f
commit
071881a9fa
@ -23,18 +23,21 @@ function Chan(attr) {
|
|||||||
}, attr));
|
}, attr));
|
||||||
}
|
}
|
||||||
|
|
||||||
Chan.prototype.sortUsers = function() {
|
Chan.prototype.sortUsers = function(irc) {
|
||||||
this.users = _.sortBy(
|
var userModeSortPriority = {};
|
||||||
this.users,
|
irc.network.options.PREFIX.forEach(function(prefix, index) {
|
||||||
function(u) { return u.name.toLowerCase(); }
|
userModeSortPriority[prefix.symbol] = index;
|
||||||
);
|
});
|
||||||
|
|
||||||
["+", "%", "@", "&", "~"].forEach(function(mode) {
|
userModeSortPriority[""] = 99; // No mode is lowest
|
||||||
this.users = _.remove(
|
|
||||||
this.users,
|
this.users = this.users.sort(function(a, b) {
|
||||||
function(u) { return u.mode === mode; }
|
if (a.mode === b.mode) {
|
||||||
).concat(this.users);
|
return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1;
|
||||||
}, this);
|
}
|
||||||
|
|
||||||
|
return userModeSortPriority[a.mode] - userModeSortPriority[b.mode];
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Chan.prototype.getMode = function(name) {
|
Chan.prototype.getMode = function(name) {
|
||||||
|
@ -19,7 +19,7 @@ module.exports = function(irc, network) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
chan.users.push(new User({nick: data.nick, modes: ""}));
|
chan.users.push(new User({nick: data.nick, modes: ""}));
|
||||||
chan.sortUsers();
|
chan.sortUsers(irc);
|
||||||
client.emit("users", {
|
client.emit("users", {
|
||||||
chan: chan.id
|
chan: chan.id
|
||||||
});
|
});
|
||||||
|
@ -19,7 +19,7 @@ module.exports = function(irc, network) {
|
|||||||
|
|
||||||
chan.users.push(user);
|
chan.users.push(user);
|
||||||
});
|
});
|
||||||
chan.sortUsers();
|
chan.sortUsers(irc);
|
||||||
client.emit("users", {
|
client.emit("users", {
|
||||||
chan: chan.id
|
chan: chan.id
|
||||||
});
|
});
|
||||||
|
@ -29,7 +29,7 @@ module.exports = function(irc, network) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
user.name = data.newnick;
|
user.name = data.newnick;
|
||||||
chan.sortUsers();
|
chan.sortUsers(irc);
|
||||||
client.emit("users", {
|
client.emit("users", {
|
||||||
chan: chan.id
|
chan: chan.id
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user