Revert "user: don't force existence of constructor properties"

This reverts commit c3e3322a79.
This commit is contained in:
Reto Brunner 2023-03-19 21:58:14 +01:00
parent c30da27f95
commit 3ac9c36d95

View File

@ -1,29 +1,32 @@
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
away: string; mode!: string;
nick: string; away!: string;
lastMessage: number; nick!: string;
lastMessage!: number;
constructor(attr: Partial<User>, prefix?: Prefix) { constructor(attr: Partial<User>, prefix?: Prefix) {
this.modes = []; _.defaults(this, attr, {
this.away = ""; modes: [],
this.nick = ""; away: "",
this.lastMessage = 0; nick: "",
lastMessage: 0,
});
if (attr) { Object.defineProperty(this, "mode", {
Object.assign(this, attr); get() {
} // 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]);