models/network: unfuck client export

This commit is contained in:
Reto Brunner 2024-03-03 12:36:26 +01:00
parent 6984e8f25a
commit 636b5c5b04

View file

@ -11,16 +11,7 @@ import ClientCertificate, {ClientCertificateType} from "../plugins/clientCertifi
import Client from "../client"; import Client from "../client";
import {MessageType} from "../../shared/types/msg"; import {MessageType} from "../../shared/types/msg";
import {ChanType} from "../../shared/types/chan"; import {ChanType} from "../../shared/types/chan";
import {SharedNetwork} from "../../shared/types/network";
/**
* List of keys which should be sent to the client by default.
*/
const fieldsForClient = {
uuid: true,
name: true,
nick: true,
serverOptions: true,
};
type NetworkIrcOptions = { type NetworkIrcOptions = {
host: string; host: string;
@ -507,24 +498,17 @@ class Network {
} }
} }
getFilteredClone(lastActiveChannel?: number, lastMessage?: number) { getFilteredClone(lastActiveChannel?: number, lastMessage?: number): SharedNetwork {
const filteredNetwork = Object.keys(this).reduce((newNetwork, prop) => { return {
if (prop === "channels") { uuid: this.uuid,
// Channels objects perform their own cloning name: this.name,
newNetwork[prop] = this[prop].map((channel) => nick: this.nick,
channel.getFilteredClone(lastActiveChannel, lastMessage) serverOptions: this.serverOptions,
); status: this.getNetworkStatus(),
} else if (fieldsForClient[prop]) { channels: this.channels.map((channel) =>
// Some properties that are not useful for the client are skipped channel.getFilteredClone(lastActiveChannel, lastMessage)
newNetwork[prop] = this[prop]; ),
} };
return newNetwork;
}, {}) as Network;
filteredNetwork.status = this.getNetworkStatus();
return filteredNetwork;
} }
getNetworkStatus() { getNetworkStatus() {