From a9f97ddf2204029406557ee8bf81b24b32537ce6 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 18 Dec 2019 00:11:11 +0200 Subject: [PATCH] Send 100 actual messages when requesting history with hidden or condensed status messages --- client/components/MessageList.vue | 1 + src/client.js | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/client/components/MessageList.vue b/client/components/MessageList.vue index 6858141f..ec1c90d5 100644 --- a/client/components/MessageList.vue +++ b/client/components/MessageList.vue @@ -247,6 +247,7 @@ export default { socket.emit("more", { target: this.channel.id, lastId: lastMessage, + condensed: this.$store.state.settings.statusMessages !== "shown", }); }, onLoadButtonObserved(entries) { diff --git a/src/client.js b/src/client.js index b7e69b10..e15f96e7 100644 --- a/src/client.js +++ b/src/client.js @@ -11,6 +11,7 @@ const Helper = require("./helper"); const UAParser = require("ua-parser-js"); const uuidv4 = require("uuid/v4"); const escapeRegExp = require("lodash/escapeRegExp"); +const constants = require("../client/js/constants.js"); const inputs = require("./plugins/inputs"); 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 (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 {