Send 100 actual messages when requesting history with hidden or condensed status messages

This commit is contained in:
Pavel Djundik 2019-12-18 00:11:11 +02:00
parent 4a345eb6d9
commit a9f97ddf22
2 changed files with 27 additions and 1 deletions

View File

@ -247,6 +247,7 @@ export default {
socket.emit("more", { socket.emit("more", {
target: this.channel.id, target: this.channel.id,
lastId: lastMessage, lastId: lastMessage,
condensed: this.$store.state.settings.statusMessages !== "shown",
}); });
}, },
onLoadButtonObserved(entries) { onLoadButtonObserved(entries) {

View File

@ -11,6 +11,7 @@ const Helper = require("./helper");
const UAParser = require("ua-parser-js"); const UAParser = require("ua-parser-js");
const uuidv4 = require("uuid/v4"); const uuidv4 = require("uuid/v4");
const escapeRegExp = require("lodash/escapeRegExp"); const escapeRegExp = require("lodash/escapeRegExp");
const constants = require("../client/js/constants.js");
const inputs = require("./plugins/inputs"); const inputs = require("./plugins/inputs");
const PublicClient = require("./plugins/packages/publicClient"); const PublicClient = require("./plugins/packages/publicClient");
@ -466,7 +467,31 @@ Client.prototype.more = function(data) {
// If requested id is not found, an empty array will be sent // If requested id is not found, an empty array will be sent
if (index > 0) { if (index > 0) {
messages = chan.messages.slice(Math.max(0, index - 100), index); let startIndex = index;
if (data.condensed) {
// Limit to 1000 messages (that's 10x normal limit)
const indexToStop = Math.max(0, index - 1000);
let realMessagesLeft = 100;
for (let i = index - 1; i >= indexToStop; i--) {
startIndex--;
// Do not count condensed messages towards the 100 messages
if (constants.condensedTypes.has(chan.messages[i].type)) {
continue;
}
// Count up actual 100 visible messages
if (--realMessagesLeft === 0) {
break;
}
}
} else {
startIndex = Math.max(0, index - 100);
}
messages = chan.messages.slice(startIndex, index);
} }
return { return {