mirror of
https://github.com/thelounge/thelounge
synced 2024-11-25 21:40:22 +00:00
models/network: unfuck client export
This commit is contained in:
parent
6984e8f25a
commit
636b5c5b04
1 changed files with 12 additions and 28 deletions
|
@ -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,
|
||||||
|
serverOptions: this.serverOptions,
|
||||||
|
status: this.getNetworkStatus(),
|
||||||
|
channels: this.channels.map((channel) =>
|
||||||
channel.getFilteredClone(lastActiveChannel, lastMessage)
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getNetworkStatus() {
|
getNetworkStatus() {
|
||||||
|
|
Loading…
Reference in a new issue