From c3e3322a79d918198bb6700169c84281c00bf8cf Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Mon, 30 Jan 2023 01:38:28 +0100 Subject: [PATCH] user: don't force existence of constructor properties --- server/models/user.ts | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/server/models/user.ts b/server/models/user.ts index ea2d39b0..0a58c3cd 100644 --- a/server/models/user.ts +++ b/server/models/user.ts @@ -1,32 +1,29 @@ -import _ from "lodash"; import Prefix from "./prefix"; class User { - modes!: string[]; + modes: string[]; // Users in the channel have only one mode assigned - mode!: string; - away!: string; - nick!: string; - lastMessage!: number; + away: string; + nick: string; + lastMessage: number; constructor(attr: Partial, prefix?: Prefix) { - _.defaults(this, attr, { - modes: [], - away: "", - nick: "", - lastMessage: 0, - }); + this.modes = []; + this.away = ""; + this.nick = ""; + this.lastMessage = 0; - Object.defineProperty(this, "mode", { - get() { - // eslint-disable-next-line @typescript-eslint/no-unsafe-return - return this.modes[0] || ""; - }, - }); + if (attr) { + Object.assign(this, attr); + } 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]);