mirror of
https://github.com/thelounge/thelounge
synced 2024-11-26 05:50:22 +00:00
user: don't force existence of constructor properties
This commit is contained in:
parent
f785acb07d
commit
c3e3322a79
1 changed files with 15 additions and 18 deletions
|
@ -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<User>, 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]);
|
||||
|
|
Loading…
Reference in a new issue