From 636b5c5b0471d652fa15f1815a1b862325c02a6c Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Sun, 3 Mar 2024 12:36:26 +0100 Subject: [PATCH] models/network: unfuck client export --- server/models/network.ts | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/server/models/network.ts b/server/models/network.ts index 07e65f1b..65d94630 100644 --- a/server/models/network.ts +++ b/server/models/network.ts @@ -11,16 +11,7 @@ import ClientCertificate, {ClientCertificateType} from "../plugins/clientCertifi import Client from "../client"; import {MessageType} from "../../shared/types/msg"; import {ChanType} from "../../shared/types/chan"; - -/** - * List of keys which should be sent to the client by default. - */ -const fieldsForClient = { - uuid: true, - name: true, - nick: true, - serverOptions: true, -}; +import {SharedNetwork} from "../../shared/types/network"; type NetworkIrcOptions = { host: string; @@ -507,24 +498,17 @@ class Network { } } - getFilteredClone(lastActiveChannel?: number, lastMessage?: number) { - const filteredNetwork = Object.keys(this).reduce((newNetwork, prop) => { - if (prop === "channels") { - // Channels objects perform their own cloning - newNetwork[prop] = this[prop].map((channel) => - channel.getFilteredClone(lastActiveChannel, lastMessage) - ); - } else if (fieldsForClient[prop]) { - // Some properties that are not useful for the client are skipped - newNetwork[prop] = this[prop]; - } - - return newNetwork; - }, {}) as Network; - - filteredNetwork.status = this.getNetworkStatus(); - - return filteredNetwork; + getFilteredClone(lastActiveChannel?: number, lastMessage?: number): SharedNetwork { + return { + uuid: this.uuid, + name: this.name, + nick: this.nick, + serverOptions: this.serverOptions, + status: this.getNetworkStatus(), + channels: this.channels.map((channel) => + channel.getFilteredClone(lastActiveChannel, lastMessage) + ), + }; } getNetworkStatus() {