thelounge/client/js/socket-events/more.ts
Reto Brunner bfca0ca612 fix more
2024-04-21 15:11:52 +02:00

30 lines
829 B
TypeScript

import {nextTick} from "vue";
import socket from "../socket";
import {store} from "../store";
import type {ClientChan, ClientMessage} from "../types";
socket.on("more", async (data) => {
const channel = store.getters.findChannel(data.chan)?.channel;
if (!channel) {
return;
}
channel.inputHistory = channel.inputHistory.concat(
data.messages
.filter((m) => m.self && m.text && m.type === "message")
// TS is too stupid to see the guard in .filter(), so we monkey patch it
// to please the compiler
.map((m) => (m.text ? m.text : ""))
.reverse()
.slice(0, 100 - channel.inputHistory.length)
);
channel.moreHistoryAvailable =
data.totalMessages > channel.messages.length + data.messages.length;
channel.messages.unshift(...data.messages);
await nextTick();
channel.historyLoading = false;
});