Merge pull request #4684 from thelounge/userProps
user: don't force existence of constructor properties
This commit is contained in:
commit
d10a59395c
@ -1,32 +1,29 @@
|
|||||||
import _ from "lodash";
|
|
||||||
import Prefix from "./prefix";
|
import Prefix from "./prefix";
|
||||||
|
|
||||||
class User {
|
class User {
|
||||||
modes!: string[];
|
modes: string[];
|
||||||
// Users in the channel have only one mode assigned
|
// Users in the channel have only one mode assigned
|
||||||
mode!: string;
|
away: string;
|
||||||
away!: string;
|
nick: string;
|
||||||
nick!: string;
|
lastMessage: number;
|
||||||
lastMessage!: number;
|
|
||||||
|
|
||||||
constructor(attr: Partial<User>, prefix?: Prefix) {
|
constructor(attr: Partial<User>, prefix?: Prefix) {
|
||||||
_.defaults(this, attr, {
|
this.modes = [];
|
||||||
modes: [],
|
this.away = "";
|
||||||
away: "",
|
this.nick = "";
|
||||||
nick: "",
|
this.lastMessage = 0;
|
||||||
lastMessage: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
Object.defineProperty(this, "mode", {
|
if (attr) {
|
||||||
get() {
|
Object.assign(this, attr);
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
}
|
||||||
return this.modes[0] || "";
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
this.setModes(this.modes, prefix || new Prefix([]));
|
this.setModes(this.modes, prefix || new Prefix([]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get mode() {
|
||||||
|
return this.modes[0] || "";
|
||||||
|
}
|
||||||
|
|
||||||
setModes(modes: string[], prefix: Prefix) {
|
setModes(modes: string[], prefix: Prefix) {
|
||||||
// irc-framework sets character mode, but The Lounge works with symbols
|
// irc-framework sets character mode, but The Lounge works with symbols
|
||||||
this.modes = modes.map((mode) => prefix.modeToSymbol[mode]);
|
this.modes = modes.map((mode) => prefix.modeToSymbol[mode]);
|
||||||
|
Loading…
Reference in New Issue
Block a user