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