Skip to content

Commit

Permalink
Revert "user: don't force existence of constructor properties"
Browse files Browse the repository at this point in the history
This reverts commit c3e3322.
  • Loading branch information
brunnre8 committed Mar 19, 2023
1 parent c30da27 commit 3ac9c36
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions server/models/user.ts
Original file line number Diff line number Diff line change
@@ -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;

if (attr) {
Object.assign(this, attr);
}
_.defaults(this, attr, {
modes: [],
away: "",
nick: "",
lastMessage: 0,
});

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]);
Expand Down

0 comments on commit 3ac9c36

Please sign in to comment.