Merge pull request #1195 from thelounge/xpaw/consistent-user-object
Do not store unnecessary information in user objects
This commit is contained in:
commit
5a5bf823a0
@ -417,7 +417,7 @@ $(function() {
|
|||||||
nicks = [];
|
nicks = [];
|
||||||
|
|
||||||
for (i in data.users) {
|
for (i in data.users) {
|
||||||
nicks.push(data.users[i].name);
|
nicks.push(data.users[i].nick);
|
||||||
}
|
}
|
||||||
|
|
||||||
nicks = nicks.sort(function(a, b) {
|
nicks = nicks.sort(function(a, b) {
|
||||||
|
@ -6,6 +6,6 @@
|
|||||||
{{/unless}}
|
{{/unless}}
|
||||||
<div class="user-mode {{modes mode}}">
|
<div class="user-mode {{modes mode}}">
|
||||||
{{/diff}}
|
{{/diff}}
|
||||||
<span role="button" class="user {{colorClass name}}" data-name="{{name}}">{{mode}}{{name}}</span>
|
<span role="button" class="user {{colorClass nick}}" data-name="{{nick}}">{{mode}}{{nick}}</span>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -77,7 +77,7 @@ Chan.prototype.sortUsers = function(irc) {
|
|||||||
|
|
||||||
this.users = this.users.sort(function(a, b) {
|
this.users = this.users.sort(function(a, b) {
|
||||||
if (a.mode === b.mode) {
|
if (a.mode === b.mode) {
|
||||||
return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1;
|
return a.nick.toLowerCase() < b.nick.toLowerCase() ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return userModeSortPriority[a.mode] - userModeSortPriority[b.mode];
|
return userModeSortPriority[a.mode] - userModeSortPriority[b.mode];
|
||||||
@ -85,7 +85,7 @@ Chan.prototype.sortUsers = function(irc) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Chan.prototype.getMode = function(name) {
|
Chan.prototype.getMode = function(name) {
|
||||||
var user = _.find(this.users, {name: name});
|
var user = _.find(this.users, {nick: name});
|
||||||
if (user) {
|
if (user) {
|
||||||
return user.mode;
|
return user.mode;
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,21 @@ module.exports = User;
|
|||||||
function User(attr, prefixLookup) {
|
function User(attr, prefixLookup) {
|
||||||
_.defaults(this, attr, {
|
_.defaults(this, attr, {
|
||||||
modes: [],
|
modes: [],
|
||||||
|
mode: "",
|
||||||
nick: ""
|
nick: ""
|
||||||
});
|
});
|
||||||
|
|
||||||
// irc-framework sets character mode, but lounge works with symbols
|
// irc-framework sets character mode, but lounge works with symbols
|
||||||
this.modes = this.modes.map(mode => prefixLookup[mode]);
|
this.modes = this.modes.map(mode => prefixLookup[mode]);
|
||||||
|
|
||||||
// TODO: Remove this
|
if (this.modes[0]) {
|
||||||
this.name = this.nick;
|
this.mode = this.modes[0];
|
||||||
this.mode = (this.modes && this.modes[0]) || "";
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
User.prototype.toJSON = function() {
|
||||||
|
return {
|
||||||
|
nick: this.nick,
|
||||||
|
mode: this.mode,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
@ -14,7 +14,7 @@ module.exports = function(irc, network) {
|
|||||||
if (data.kicked === irc.user.nick) {
|
if (data.kicked === irc.user.nick) {
|
||||||
chan.users = [];
|
chan.users = [];
|
||||||
} else {
|
} else {
|
||||||
chan.users = _.without(chan.users, _.find(chan.users, {name: data.kicked}));
|
chan.users = _.without(chan.users, _.find(chan.users, {nick: data.kicked}));
|
||||||
}
|
}
|
||||||
|
|
||||||
client.emit("users", {
|
client.emit("users", {
|
||||||
|
@ -81,7 +81,7 @@ module.exports = function(irc, network) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = _.find(targetChan.users, {name: mode.param});
|
const user = _.find(targetChan.users, {nick: mode.param});
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,12 @@ module.exports = function(irc, network) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
chan.users = data.users.map(u => new User(u, network.prefixLookup));
|
chan.users = data.users.map(user => {
|
||||||
|
return new User({
|
||||||
|
nick: user.nick,
|
||||||
|
modes: user.modes,
|
||||||
|
}, network.prefixLookup);
|
||||||
|
});
|
||||||
|
|
||||||
chan.sortUsers(irc);
|
chan.sortUsers(irc);
|
||||||
|
|
||||||
|
@ -25,11 +25,11 @@ module.exports = function(irc, network) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
network.channels.forEach(chan => {
|
network.channels.forEach(chan => {
|
||||||
var user = _.find(chan.users, {name: data.nick});
|
var user = _.find(chan.users, {nick: data.nick});
|
||||||
if (typeof user === "undefined") {
|
if (typeof user === "undefined") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
user.name = data.new_nick;
|
user.nick = data.new_nick;
|
||||||
chan.sortUsers(irc);
|
chan.sortUsers(irc);
|
||||||
client.emit("users", {
|
client.emit("users", {
|
||||||
chan: chan.id
|
chan: chan.id
|
||||||
|
@ -18,7 +18,7 @@ module.exports = function(irc, network) {
|
|||||||
chan: chan.id
|
chan: chan.id
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var user = _.find(chan.users, {name: from});
|
var user = _.find(chan.users, {nick: from});
|
||||||
chan.users = _.without(chan.users, user);
|
chan.users = _.without(chan.users, user);
|
||||||
client.emit("users", {
|
client.emit("users", {
|
||||||
chan: chan.id
|
chan: chan.id
|
||||||
|
@ -8,7 +8,7 @@ module.exports = function(irc, network) {
|
|||||||
irc.on("quit", function(data) {
|
irc.on("quit", function(data) {
|
||||||
network.channels.forEach(chan => {
|
network.channels.forEach(chan => {
|
||||||
var from = data.nick;
|
var from = data.nick;
|
||||||
var user = _.find(chan.users, {name: from});
|
var user = _.find(chan.users, {nick: from});
|
||||||
if (typeof user === "undefined") {
|
if (typeof user === "undefined") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,7 @@ describe("Chan", function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var getUserNames = function(chan) {
|
var getUserNames = function(chan) {
|
||||||
return chan.users.map(function(u) {
|
return chan.users.map(u => u.nick);
|
||||||
return u.name;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
it("should sort a simple user list", function() {
|
it("should sort a simple user list", function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user