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";
class User {
modes: string[];
modes!: string[];
// Users in the channel have only one mode assigned
away: string;
nick: string;
lastMessage: number;
mode!: string;
away!: string;
nick!: string;
lastMessage!: number;
constructor(attr: Partial<User>, prefix?: Prefix) {
this.modes = [];
this.away = "";
this.nick = "";
this.lastMessage = 0;
_.defaults(this, attr, {
modes: [],
away: "",
nick: "",
lastMessage: 0,
});
if (attr) {
Object.assign(this, attr);
}
Object.defineProperty(this, "mode", {
get() {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return this.modes[0] || "";
},
});
this.setModes(this.modes, prefix || new Prefix([]));
}
get mode() {
return this.modes[0] || "";
}
setModes(modes: string[], prefix: Prefix) {
// irc-framework sets character mode, but The Lounge works with symbols
this.modes = modes.map((mode) => prefix.modeToSymbol[mode]);