hardlounge/client/js/socket-events/more.js
Nachtalb 04cf2277d9
Prevent possible error when findChannel can't find the wanted channel
Using ?. (optional chaining) requires ecma version 2020 as it is fairly new. Webpack / Babel can handle it.
2021-05-05 18:09:18 +02:00

30 lines
669 B
JavaScript

"use strict";
import Vue from "vue";
import socket from "../socket";
import store from "../store";
socket.on("more", function (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")
.map((m) => m.text)
.reverse()
.slice(null, 100 - channel.inputHistory.length)
);
channel.moreHistoryAvailable =
data.totalMessages > channel.messages.length + data.messages.length;
channel.messages.unshift(...data.messages);
Vue.nextTick(() => {
channel.historyLoading = false;
});
});