Merge pull request #4683 from thelounge/chanProps

models/chan: don't force existence of constructor properties
This commit is contained in:
Max Leiter 2023-02-26 17:22:06 -08:00 committed by GitHub
commit 8fc696620f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,19 +34,18 @@ export type FilteredChannel = Chan & {
}; };
class Chan { class Chan {
// TODO: don't force existence, figure out how to make TS infer it. id: number;
id!: number; messages: Msg[];
messages!: Msg[]; name: string;
name!: string; key: string;
key!: string; topic: string;
topic!: string; firstUnread: number;
firstUnread!: number; unread: number;
unread!: number; highlight: number;
highlight!: number; users: Map<string, User>;
users!: Map<string, User>; muted: boolean;
muted!: boolean; type: ChanType;
type!: ChanType; state: ChanState;
state!: ChanState;
userAway?: boolean; userAway?: boolean;
special?: SpecialChanType; special?: SpecialChanType;
@ -56,20 +55,22 @@ 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>) {
_.defaults(this, attr, { this.id = 0;
id: 0, this.messages = [];
messages: [], this.name = "";
name: "", this.key = "";
key: "", this.topic = "";
topic: "", this.type = ChanType.CHANNEL;
type: ChanType.CHANNEL, this.state = ChanState.PARTED;
state: ChanState.PARTED, this.firstUnread = 0;
firstUnread: 0, this.unread = 0;
unread: 0, this.highlight = 0;
highlight: 0, this.users = new Map();
users: new Map(), this.muted = false;
muted: false,
}); if (attr) {
Object.assign(this, attr);
}
} }
destroy() { destroy() {