thelounge/src/models/user.js
Reto 8fcd079204
Properly track user modes for context menu (#4267)
* properly track user modes for context menu

The RPL_ISUPPORT response contains a PREFIX element, which not only tracks the
prefix chars ("@", "+" etc) but also their corresponding mode chars (+O, +v)
This commit changes the context menu to not rely on a hardcoded list but rather
user the one given in the prefix response by the server.

Co-authored-by: Max Leiter <maxwell.leiter@gmail.com>
2021-07-21 00:30:07 -07:00

36 lines
636 B
JavaScript

"use strict";
const _ = require("lodash");
module.exports = User;
function User(attr, prefix) {
_.defaults(this, attr, {
modes: [],
away: "",
nick: "",
lastMessage: 0,
});
Object.defineProperty(this, "mode", {
get() {
return this.modes[0] || "";
},
});
this.setModes(this.modes, prefix);
}
User.prototype.setModes = function (modes, prefix) {
// irc-framework sets character mode, but The Lounge works with symbols
this.modes = modes.map((mode) => prefix.modeToSymbol[mode]);
};
User.prototype.toJSON = function () {
return {
nick: this.nick,
modes: this.modes,
lastMessage: this.lastMessage,
};
};