This commit is contained in:
Reto Brunner 2024-02-24 14:03:05 +01:00
parent d716402da2
commit 12a0b0b6f9
3 changed files with 46 additions and 11 deletions

View file

@ -1,8 +1,8 @@
import {defineComponent} from "vue";
import Network from "../../server/models/network";
import {SharedMessage} from "../../shared/types/msg";
import {SharedChan} from "../../shared/types/chan";
import {SharedNetwork} from "../../shared/types/network";
import {SharedUser} from "../../shared/models/user";
import {SharedMention} from "../../shared/models/mention";
import {ClientConfiguration} from "../../server/server";
@ -46,7 +46,7 @@ type InitClientChan = ClientChan & {
};
// We omit channels so we can use ClientChan[] instead of Chan[]
type ClientNetwork = Omit<Network, "channels"> & {
type ClientNetwork = Omit<SharedNetwork, "channels"> & {
isJoinChannelShown: boolean;
isCollapsed: boolean;
channels: ClientChan[];

View file

@ -9,12 +9,7 @@ import Network from "./network";
import Prefix from "./prefix";
import {MessageType} from "../../shared/types/msg";
import {ChanType, SpecialChanType, ChanState} from "../../shared/types/chan";
// eslint-disable-next-line no-use-before-define
export type FilteredChannel = Chan & {
users: [];
totalMessages: number;
};
import {SharedNetworkChan} from "../../shared/types/network";
export type ChanConfig = {
name: string;
@ -189,7 +184,10 @@ class Chan {
* If true, channel is assumed active.
* @param {int} lastMessage - Last message id seen by active client to avoid sending duplicates.
*/
getFilteredClone(lastActiveChannel?: number | boolean, lastMessage?: number): FilteredChannel {
getFilteredClone(
lastActiveChannel?: number | boolean,
lastMessage?: number
): SharedNetworkChan {
return Object.keys(this).reduce((newChannel, prop) => {
if (Chan.optionalProperties.includes(prop)) {
if (this[prop] !== undefined || (Array.isArray(this[prop]) && this[prop].length)) {
@ -213,13 +211,13 @@ class Chan {
newChannel[prop] = this[prop].slice(-messagesToSend);
}
(newChannel as FilteredChannel).totalMessages = this[prop].length;
(newChannel as SharedNetworkChan).totalMessages = this[prop].length;
} else {
newChannel[prop] = this[prop];
}
return newChannel;
}, {}) as FilteredChannel;
}, {}) as SharedNetworkChan;
}
writeUserLog(client: Client, msg: Msg) {
this.messages.push(msg);

37
shared/types/network.ts Normal file
View file

@ -0,0 +1,37 @@
import {SharedChan} from "./chan";
export type SharedPrefixObject = {
symbol: string;
mode: string;
};
export type SharedNetworkChan = SharedChan & {
users: []; // TODO: this thing appears useless
totalMessages: number;
};
export type SharedPrefix = {
prefix: SharedPrefixObject[];
modeToSymbol: {[mode: string]: string};
symbols: string[];
};
export type SharedServerOptions = {
CHANTYPES: string[];
PREFIX: SharedPrefix;
NETWORK: string;
};
export type SharedNetworkStatus = {
connected: boolean;
secure: boolean;
};
export type SharedNetwork = {
uuid: string;
name: string;
nick: string;
serverOptions: SharedServerOptions;
status: SharedNetworkStatus;
channels: SharedNetworkChan[];
};