Revert "models/chan: don't force existence of constructor properties"

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

View file

@ -41,18 +41,19 @@ export type ChanConfig = {
}; };
class Chan { class Chan {
id: number; // TODO: don't force existence, figure out how to make TS infer it.
messages: Msg[]; id!: number;
name: string; messages!: Msg[];
key: string; name!: string;
topic: string; key!: string;
firstUnread: number; topic!: string;
unread: number; firstUnread!: number;
highlight: number; unread!: number;
users: Map<string, User>; highlight!: number;
muted: boolean; users!: Map<string, User>;
type: ChanType; muted!: boolean;
state: ChanState; type!: ChanType;
state!: ChanState;
userAway?: boolean; userAway?: boolean;
special?: SpecialChanType; special?: SpecialChanType;
@ -62,22 +63,20 @@ class Chan {
static optionalProperties = ["userAway", "special", "data", "closed", "num_users"]; static optionalProperties = ["userAway", "special", "data", "closed", "num_users"];
constructor(attr?: Partial<Chan>) { constructor(attr?: Partial<Chan>) {
this.id = 0; _.defaults(this, attr, {
this.messages = []; id: 0,
this.name = ""; messages: [],
this.key = ""; name: "",
this.topic = ""; key: "",
this.type = ChanType.CHANNEL; topic: "",
this.state = ChanState.PARTED; type: ChanType.CHANNEL,
this.firstUnread = 0; state: ChanState.PARTED,
this.unread = 0; firstUnread: 0,
this.highlight = 0; unread: 0,
this.users = new Map(); highlight: 0,
this.muted = false; users: new Map(),
muted: false,
if (attr) { });
Object.assign(this, attr);
}
} }
destroy() { destroy() {