2022-06-18 16:25:21 -08:00
|
|
|
import {nextTick} from "vue";
|
2019-11-11 23:39:09 +02:00
|
|
|
|
2019-11-16 19:24:03 +02:00
|
|
|
import socket from "../socket";
|
2022-06-18 16:25:21 -08:00
|
|
|
import {store} from "../store";
|
2024-03-01 09:04:30 +01:00
|
|
|
import {ClientMessage} from "../../../shared/types/msg";
|
2017-05-18 21:08:54 +01:00
|
|
|
|
2022-06-18 16:25:21 -08:00
|
|
|
socket.on("more", async (data) => {
|
2021-05-05 18:09:18 +02:00
|
|
|
const channel = store.getters.findChannel(data.chan)?.channel;
|
2018-02-20 09:28:04 +02:00
|
|
|
|
2018-07-08 15:18:17 +03:00
|
|
|
if (!channel) {
|
|
|
|
return;
|
2017-05-18 21:08:54 +01:00
|
|
|
}
|
|
|
|
|
2021-05-01 01:46:55 +02:00
|
|
|
channel.inputHistory = channel.inputHistory.concat(
|
|
|
|
data.messages
|
|
|
|
.filter((m) => m.self && m.text && m.type === "message")
|
2024-03-01 09:04:30 +01:00
|
|
|
// 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 : ""))
|
2021-05-01 01:46:55 +02:00
|
|
|
.reverse()
|
2022-06-18 16:25:21 -08:00
|
|
|
.slice(0, 100 - channel.inputHistory.length)
|
2021-05-01 01:46:55 +02:00
|
|
|
);
|
2021-05-01 01:36:44 +02:00
|
|
|
channel.moreHistoryAvailable =
|
|
|
|
data.totalMessages > channel.messages.length + data.messages.length;
|
2024-03-01 09:04:30 +01:00
|
|
|
// TODO: invalid type cast
|
2022-06-18 16:25:21 -08:00
|
|
|
channel.messages.unshift(...(data.messages as ClientMessage[]));
|
2018-07-12 19:25:41 +03:00
|
|
|
|
2022-06-18 16:25:21 -08:00
|
|
|
await nextTick();
|
|
|
|
channel.historyLoading = false;
|
2017-05-18 21:08:54 +01:00
|
|
|
});
|