mirror of
https://github.com/thelounge/thelounge
synced 2024-11-25 05:20:21 +00:00
wip: unbork init progress
This commit is contained in:
parent
0067c30273
commit
f5c691f37b
7 changed files with 51 additions and 44 deletions
34
client/js/chan.ts
Normal file
34
client/js/chan.ts
Normal 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;
|
||||||
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
import {ActionContext, createStore, Store, useStore as baseUseStore} from "vuex";
|
import {ActionContext, createStore, Store, useStore as baseUseStore} from "vuex";
|
||||||
import {createSettingsStore} from "./store-settings";
|
import {createSettingsStore} from "./store-settings";
|
||||||
import storage from "./localStorage";
|
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 type {InjectionKey} from "vue";
|
||||||
|
|
||||||
import {SettingsState} from "./settings";
|
import {SettingsState} from "./settings";
|
||||||
|
@ -125,7 +125,6 @@ type Getters = {
|
||||||
findNetwork: (state: State) => (uuid: string) => ClientNetwork | null;
|
findNetwork: (state: State) => (uuid: string) => ClientNetwork | null;
|
||||||
highlightCount(state: State): number;
|
highlightCount(state: State): number;
|
||||||
title(state: State, getters: Omit<Getters, "title">): string;
|
title(state: State, getters: Omit<Getters, "title">): string;
|
||||||
initChannel: () => (channel: InitClientChan) => ClientChan;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// getters without the state argument
|
// getters without the state argument
|
||||||
|
@ -196,31 +195,6 @@ const getters: Getters = {
|
||||||
|
|
||||||
return alertEventCount + channelname + appName;
|
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 = {
|
type Mutations = {
|
||||||
|
|
7
client/js/types.d.ts
vendored
7
client/js/types.d.ts
vendored
|
@ -5,7 +5,7 @@ import {SharedNetwork} from "../../shared/types/network";
|
||||||
import {SharedUser} from "../../shared/types/user";
|
import {SharedUser} from "../../shared/types/user";
|
||||||
import {SharedMention} from "../../shared/models/mention";
|
import {SharedMention} from "../../shared/models/mention";
|
||||||
import {SharedConfiguration, LockedSharedConfiguration} from "../../shared/types/config";
|
import {SharedConfiguration, LockedSharedConfiguration} from "../../shared/types/config";
|
||||||
import {LinkPreview} from "../../shared/types/msg";
|
import {LinkPreview, ClientMessage} from "../../shared/types/msg";
|
||||||
|
|
||||||
interface LoungeWindow extends Window {
|
interface LoungeWindow extends Window {
|
||||||
g_TheLoungeRemoveLoading?: () => void;
|
g_TheLoungeRemoveLoading?: () => void;
|
||||||
|
@ -17,10 +17,13 @@ interface LoungeWindow extends Window {
|
||||||
|
|
||||||
type ClientUser = SharedUser;
|
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"> & {
|
type ClientChan = Omit<SharedChan, "messages"> & {
|
||||||
moreHistoryAvailable: boolean;
|
moreHistoryAvailable: boolean;
|
||||||
editTopic: boolean;
|
editTopic: boolean;
|
||||||
users: ClientUser[];
|
|
||||||
messages: ClientMessage[];
|
messages: ClientMessage[];
|
||||||
|
|
||||||
// these are added in store/initChannel
|
// these are added in store/initChannel
|
||||||
|
|
|
@ -34,7 +34,7 @@ class Msg {
|
||||||
raw_modes!: any;
|
raw_modes!: any;
|
||||||
when!: Date;
|
when!: Date;
|
||||||
whois!: any;
|
whois!: any;
|
||||||
users!: UserInMessage[] | string[];
|
users!: string[];
|
||||||
statusmsgGroup!: string;
|
statusmsgGroup!: string;
|
||||||
params!: string[];
|
params!: string[];
|
||||||
|
|
||||||
|
|
|
@ -840,7 +840,7 @@ function initializeClient(
|
||||||
// socket.join is a promise depending on the adapter.
|
// socket.join is a promise depending on the adapter.
|
||||||
void socket.join(client.id);
|
void socket.join(client.id);
|
||||||
|
|
||||||
const sendInitEvent = (tokenToSend: string | null) => {
|
const sendInitEvent = (tokenToSend?: string) => {
|
||||||
socket.emit("init", {
|
socket.emit("init", {
|
||||||
active: openChannel,
|
active: openChannel,
|
||||||
networks: client.networks.map((network) =>
|
networks: client.networks.map((network) =>
|
||||||
|
@ -852,7 +852,7 @@ function initializeClient(
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Config.values.public) {
|
if (Config.values.public) {
|
||||||
sendInitEvent(null);
|
sendInitEvent();
|
||||||
} else if (!token) {
|
} else if (!token) {
|
||||||
client.generateToken((newToken) => {
|
client.generateToken((newToken) => {
|
||||||
token = client.calculateTokenHash(newToken);
|
token = client.calculateTokenHash(newToken);
|
||||||
|
@ -863,7 +863,7 @@ function initializeClient(
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
client.updateSession(token, getClientIp(socket), socket.request);
|
client.updateSession(token, getClientIp(socket), socket.request);
|
||||||
sendInitEvent(null);
|
sendInitEvent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,12 +61,12 @@ export type LinkPreview = {
|
||||||
|
|
||||||
export type SharedMsg = {
|
export type SharedMsg = {
|
||||||
from?: UserInMessage;
|
from?: UserInMessage;
|
||||||
id?: number;
|
id: number;
|
||||||
previews?: LinkPreview[];
|
previews?: LinkPreview[];
|
||||||
text?: string;
|
text?: string;
|
||||||
type?: MessageType;
|
type?: MessageType;
|
||||||
self?: boolean;
|
self?: boolean;
|
||||||
time?: Date;
|
time: Date;
|
||||||
hostmask?: string;
|
hostmask?: string;
|
||||||
target?: UserInMessage;
|
target?: UserInMessage;
|
||||||
// TODO: new_nick is only on MessageType.NICK,
|
// TODO: new_nick is only on MessageType.NICK,
|
||||||
|
@ -92,13 +92,9 @@ export type SharedMsg = {
|
||||||
raw_modes?: any;
|
raw_modes?: any;
|
||||||
when?: Date;
|
when?: Date;
|
||||||
whois?: any;
|
whois?: any;
|
||||||
users?: UserInMessage[] | string[];
|
|
||||||
|
users: string[];
|
||||||
|
|
||||||
statusmsgGroup?: string;
|
statusmsgGroup?: string;
|
||||||
params?: string[];
|
params?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ClientMessage = Omit<SharedMsg, "users"> & {
|
|
||||||
time: Date;
|
|
||||||
users: string[];
|
|
||||||
id: number;
|
|
||||||
};
|
|
||||||
|
|
4
shared/types/socket-events.d.ts
vendored
4
shared/types/socket-events.d.ts
vendored
|
@ -81,9 +81,9 @@ interface ServerToClientEvents {
|
||||||
|
|
||||||
"msg:preview": EventHandler<{id: number; chan: number; preview: LinkPreview}>;
|
"msg:preview": EventHandler<{id: number; chan: number; preview: LinkPreview}>;
|
||||||
"msg:special": EventHandler<{chan: number; data?: Record<string, any>}>;
|
"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;
|
"search:results": (response: SearchResponse) => void;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue