Remove some unnecessary code

This commit is contained in:
Pavel Djundik 2018-07-09 16:42:03 +03:00 committed by Pavel Djundik
parent 8e64670b4e
commit aea779cfdf
4 changed files with 4 additions and 95 deletions

View file

@ -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);

View file

@ -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

View file

@ -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");
}
}

View file

@ -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);