From aea779cfdfce8e2bba727d6e6ab877290603dde0 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Mon, 9 Jul 2018 16:42:03 +0300 Subject: [PATCH] Remove some unnecessary code --- client/js/libs/jquery/stickyscroll.js | 55 --------------------------- client/js/lounge.js | 18 --------- client/js/renderPreview.js | 2 - client/js/socket-events/msg.js | 24 ++---------- 4 files changed, 4 insertions(+), 95 deletions(-) delete mode 100644 client/js/libs/jquery/stickyscroll.js diff --git a/client/js/libs/jquery/stickyscroll.js b/client/js/libs/jquery/stickyscroll.js deleted file mode 100644 index aad7b8b3..00000000 --- a/client/js/libs/jquery/stickyscroll.js +++ /dev/null @@ -1,55 +0,0 @@ -import jQuery from "jquery"; - -(function($) { - $.fn.unsticky = function() { - return this.trigger("unstick.sticky").off(".sticky"); - }; - - $.fn.sticky = function() { - var self = this; - var stuckToBottom = true; - var lastStick = 0; - - var keepToBottom = function() { - if (stuckToBottom) { - self.scrollBottom(); - } - }; - - $(window).on("resize.sticky", keepToBottom); - self - .on("unstick.sticky", function() { - $(window).off("resize.sticky", keepToBottom); - }) - .on("scroll.sticky", function() { - // When resizing, sometimes the browser sends a bunch of extra scroll events due to content - // reflow, so if we resized within 250ms we can assume it's one of those. The order of said - // events is not predictable, and scroll can happen last, so not setting stuckToBottom is - // not enough, we have to force the scroll still. - if (stuckToBottom && Date.now() - lastStick < 250) { - self.scrollBottom(); - } else { - stuckToBottom = self.isScrollBottom(); - } - }) - .on("scrollBottom.sticky", function() { - stuckToBottom = true; - lastStick = Date.now(); - this.scrollTop = this.scrollHeight; - }) - .on("keepToBottom.sticky", keepToBottom) - .scrollBottom(); - - return self; - }; - - $.fn.scrollBottom = function() { - this.trigger("scrollBottom.sticky"); - return this; - }; - - $.fn.isScrollBottom = function() { - var el = this[0]; - return el.scrollHeight - el.scrollTop - el.offsetHeight <= 30; - }; -})(jQuery); diff --git a/client/js/lounge.js b/client/js/lounge.js index 70047606..b0eea0df 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -11,7 +11,6 @@ const {vueApp, findChannel} = require("./vue"); window.vueMounted = () => { require("./socket-events"); - require("./libs/jquery/stickyscroll"); const slideoutMenu = require("./slideout"); const templates = require("../views"); const contextMenuFactory = require("./contextMenuFactory"); @@ -55,7 +54,6 @@ window.vueMounted = () => { const isOpen = !viewport.hasClass("userlist-open"); viewport.toggleClass("userlist-open", isOpen); - chat.find(".chan.active .chat").trigger("keepToBottom"); storeSidebarVisibility("thelounge.state.userlist", isOpen); return false; @@ -97,8 +95,6 @@ window.vueMounted = () => { // because some browsers tend to incorrently round the values when using high density // displays or using page zoom feature this.style.height = Math.ceil(this.scrollHeight / lineHeight) * lineHeight + "px"; - - chat.find(".chan.active .chat").trigger("keepToBottom"); // fix growing }); if (navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i)) { @@ -177,18 +173,6 @@ window.vueMounted = () => { lastActive .removeClass("active"); - /*const lastActiveChan = lastActive.find(".chan.active"); - - if (lastActiveChan.length > 0) { - lastActiveChan - .removeClass("active") - .find(".unread-marker") - .data("unread-id", 0) - .appendTo(lastActiveChan.find(".messages")); - - render.trimMessageInChannel(lastActiveChan, 100); - }*/ - const chan = $(target) .addClass("active") .trigger("show"); @@ -205,8 +189,6 @@ window.vueMounted = () => { const chanChat = chan.find(".chat"); if (chanChat.length > 0 && type !== "special") { - chanChat.sticky(); - // On touch devices unfocus (blur) the input to correctly close the virtual keyboard // An explicit blur is required, as the keyboard may open back up if the focus remains // See https://github.com/thelounge/thelounge/issues/2257 diff --git a/client/js/renderPreview.js b/client/js/renderPreview.js index 1f4ddf77..cfef94f0 100644 --- a/client/js/renderPreview.js +++ b/client/js/renderPreview.js @@ -102,8 +102,6 @@ function appendPreview(preview, msg, template) { if (activeChannelId === channelId) { // If this preview is in active channel, hide "More" button if necessary previewContent.trigger("showMoreIfNeeded"); - - container.trigger("keepToBottom"); } } diff --git a/client/js/socket-events/msg.js b/client/js/socket-events/msg.js index 83f3c702..2d372274 100644 --- a/client/js/socket-events/msg.js +++ b/client/js/socket-events/msg.js @@ -2,7 +2,6 @@ const $ = require("jquery"); const socket = require("../socket"); -const render = require("../render"); const utils = require("../utils"); const options = require("../options"); const cleanIrcMessage = require("../libs/handlebars/ircmessageparser/cleanIrcMessage"); @@ -23,6 +22,10 @@ try { } socket.on("msg", function(data) { + if (utils.lastMessageId < data.msg.id) { + utils.lastMessageId = data.msg.id; + } + // We set a maximum timeout of 2 seconds so that messages don't take too long to appear. utils.requestIdleCallback(() => processReceivedMessage(data), 2000); }); @@ -54,7 +57,6 @@ function processReceivedMessage(data) { const scrollContainer = channelContainer.find(".chat"); const container = channelContainer.find(".messages"); - const activeChannelId = chat.find(".chan.active").data("id"); if (data.msg.type === "channel_list" || data.msg.type === "ban_list" || data.msg.type === "ignore_list") { $(container).empty(); @@ -62,10 +64,6 @@ function processReceivedMessage(data) { channel.channel.messages.push(data.msg); - if (activeChannelId === targetId) { - scrollContainer.trigger("keepToBottom"); - } - notifyMessage(targetId, channelContainer, data); let shouldMoveMarker = data.msg.self; @@ -93,20 +91,6 @@ function processReceivedMessage(data) { .appendTo(container); } - let messageLimit = 0; - - if (activeChannelId !== targetId) { - // If message arrives in non active channel, keep only 100 messages - messageLimit = 100; - } else if (scrollContainer.isScrollBottom()) { - // If message arrives in active channel, keep 500 messages if scroll is currently at the bottom - messageLimit = 500; - } - - if (messageLimit > 0) { - render.trimMessageInChannel(channelContainer, messageLimit); - } - if ((data.msg.type === "message" || data.msg.type === "action") && channel.channel.type === "channel") { const user = channel.channel.users.find((u) => u.nick === data.msg.from.nick);