wip: unbork init progress

This commit is contained in:
Reto Brunner 2024-03-24 20:27:56 +01:00
parent 0067c30273
commit f5c691f37b
7 changed files with 51 additions and 44 deletions

34
client/js/chan.ts Normal file
View file

@ -0,0 +1,34 @@
import {ClientChan, ClientMessage} from "./types";
import {SharedNetworkChan} from "../../shared/types/network";
import {SharedMsg} from "../../shared/types/msg";
export function toClientChan(shared: SharedNetworkChan): ClientChan {
const history: string[] = [""].concat(
shared.messages
.filter((m) => m.self && m.text && m.type === "message")
// TS is too stupid to see the nil guard on filter... so we monkey patch it
.map((m): string => (m.text ? m.text : ""))
.reverse()
.slice(0, 99)
);
// filter the unused vars
const {messages, totalMessages: __, ...props} = shared;
const channel: ClientChan = {
...props,
editTopic: false,
pendingMessage: "",
inputHistoryPosition: 0,
historyLoading: false,
scrolledToBottom: true,
usersOutdated: shared.type === "channel" ? true : false,
moreHistoryAvailable: shared.totalMessages > shared.messages.length,
inputHistory: history,
messages: sharedMsgToClientMsg(messages),
};
return channel;
}
function sharedMsgToClientMsg(shared: SharedMsg[]): ClientMessage[] {
// TODO: this is a stub for now, we will want to populate client specific stuff here
return shared;
}

View file

@ -3,7 +3,7 @@
import {ActionContext, createStore, Store, useStore as baseUseStore} from "vuex";
import {createSettingsStore} from "./store-settings";
import storage from "./localStorage";
import type {ClientChan, ClientNetwork, InitClientChan, NetChan, ClientMention} from "./types";
import type {ClientChan, ClientNetwork, NetChan, ClientMention} from "./types";
import type {InjectionKey} from "vue";
import {SettingsState} from "./settings";
@ -125,7 +125,6 @@ type Getters = {
findNetwork: (state: State) => (uuid: string) => ClientNetwork | null;
highlightCount(state: State): number;
title(state: State, getters: Omit<Getters, "title">): string;
initChannel: () => (channel: InitClientChan) => ClientChan;
};
// getters without the state argument
@ -196,31 +195,6 @@ const getters: Getters = {
return alertEventCount + channelname + appName;
},
initChannel: () => (channel: InitClientChan) => {
// TODO: This should be a mutation
channel.pendingMessage = "";
channel.inputHistoryPosition = 0;
channel.inputHistory = [""].concat(
channel.messages
.filter((m) => m.self && m.text && m.type === "message")
.map((m) => m.text)
.reverse()
.slice(0, 99)
);
channel.historyLoading = false;
channel.scrolledToBottom = true;
channel.editTopic = false;
channel.moreHistoryAvailable = channel.totalMessages! > channel.messages.length;
delete channel.totalMessages;
if (channel.type === "channel") {
channel.usersOutdated = true;
}
return channel as ClientChan;
},
};
type Mutations = {

View file

@ -5,7 +5,7 @@ import {SharedNetwork} from "../../shared/types/network";
import {SharedUser} from "../../shared/types/user";
import {SharedMention} from "../../shared/models/mention";
import {SharedConfiguration, LockedSharedConfiguration} from "../../shared/types/config";
import {LinkPreview} from "../../shared/types/msg";
import {LinkPreview, ClientMessage} from "../../shared/types/msg";
interface LoungeWindow extends Window {
g_TheLoungeRemoveLoading?: () => void;
@ -17,10 +17,13 @@ interface LoungeWindow extends Window {
type ClientUser = SharedUser;
// we will eventually need to put client specific fields here
// which are not shared with the server
export type ClientMessage = SharedMsg;
type ClientChan = Omit<SharedChan, "messages"> & {
moreHistoryAvailable: boolean;
editTopic: boolean;
users: ClientUser[];
messages: ClientMessage[];
// these are added in store/initChannel

View file

@ -34,7 +34,7 @@ class Msg {
raw_modes!: any;
when!: Date;
whois!: any;
users!: UserInMessage[] | string[];
users!: string[];
statusmsgGroup!: string;
params!: string[];

View file

@ -840,7 +840,7 @@ function initializeClient(
// socket.join is a promise depending on the adapter.
void socket.join(client.id);
const sendInitEvent = (tokenToSend: string | null) => {
const sendInitEvent = (tokenToSend?: string) => {
socket.emit("init", {
active: openChannel,
networks: client.networks.map((network) =>
@ -852,7 +852,7 @@ function initializeClient(
};
if (Config.values.public) {
sendInitEvent(null);
sendInitEvent();
} else if (!token) {
client.generateToken((newToken) => {
token = client.calculateTokenHash(newToken);
@ -863,7 +863,7 @@ function initializeClient(
});
} else {
client.updateSession(token, getClientIp(socket), socket.request);
sendInitEvent(null);
sendInitEvent();
}
}

View file

@ -61,12 +61,12 @@ export type LinkPreview = {
export type SharedMsg = {
from?: UserInMessage;
id?: number;
id: number;
previews?: LinkPreview[];
text?: string;
type?: MessageType;
self?: boolean;
time?: Date;
time: Date;
hostmask?: string;
target?: UserInMessage;
// TODO: new_nick is only on MessageType.NICK,
@ -92,13 +92,9 @@ export type SharedMsg = {
raw_modes?: any;
when?: Date;
whois?: any;
users?: UserInMessage[] | string[];
users: string[];
statusmsgGroup?: string;
params?: string[];
};
export type ClientMessage = Omit<SharedMsg, "users"> & {
time: Date;
users: string[];
id: number;
};

View file

@ -81,9 +81,9 @@ interface ServerToClientEvents {
"msg:preview": EventHandler<{id: number; chan: number; preview: LinkPreview}>;
"msg:special": EventHandler<{chan: number; data?: Record<string, any>}>;
msg: EventHandler<{msg: ClientMessage; chan: number; highlight?: number; unread?: number}>;
msg: EventHandler<{msg: SharedMsg; chan: number; highlight?: number; unread?: number}>;
init: EventHandler<{active: number; networks: SharedNetwork[]; token: string}>;
init: EventHandler<{active: number; networks: SharedNetwork[]; token?: string}>;
"search:results": (response: SearchResponse) => void;