From aa1446c19d81c634d53f2e6cac295acd1066c6a9 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 10 Jul 2018 11:06:08 +0300 Subject: [PATCH] Some fixes for unread marker --- client/components/MessageList.vue | 8 +------- client/js/lounge.js | 4 ++++ client/js/socket-events/msg.js | 25 ++----------------------- client/js/socket-events/open.js | 8 +------- 4 files changed, 8 insertions(+), 37 deletions(-) diff --git a/client/components/MessageList.vue b/client/components/MessageList.vue index 9b3eb8c7..e6ca68fb 100644 --- a/client/components/MessageList.vue +++ b/client/components/MessageList.vue @@ -104,13 +104,7 @@ export default { return (new Date(previousTime.time)).getDay() !== (new Date(currentTime.time)).getDay(); }, shouldDisplayUnreadMarker(msgId) { - if (this.channel.firstUnread < msgId) { - return false; - } - - this.channel.firstUnread = 0; - - return true; + return this.channel.firstUnread === msgId; }, onCopy() { clipboard(this.$el); diff --git a/client/js/lounge.js b/client/js/lounge.js index 7feb357a..1e2a4063 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -126,6 +126,10 @@ window.vueMounted = () => { const inSidebar = self.parents("#sidebar, #footer").length > 0; let channel; + if (vueApp.activeChannel) { + vueApp.activeChannel.channel.firstUnread = vueApp.activeChannel.channel.messages[vueApp.activeChannel.channel.messages.length - 1].id; + } + if (inSidebar) { channel = findChannel(Number(self.attr("data-id"))); diff --git a/client/js/socket-events/msg.js b/client/js/socket-events/msg.js index f95f3390..36eae59b 100644 --- a/client/js/socket-events/msg.js +++ b/client/js/socket-events/msg.js @@ -64,29 +64,8 @@ function processReceivedMessage(data) { notifyMessage(targetId, channelContainer, data); - let shouldMoveMarker = data.msg.self; - - if (!shouldMoveMarker) { - const lastChild = container.children().last(); - - // If last element is hidden (e.g. hidden status messages) check the element before it. - // If it's unread marker or date marker, then move unread marker to the bottom - // so that it isn't displayed as the last element in chat. - // display properly is checked instead of using `:hidden` selector because it doesn't work in non-active channels. - if (lastChild.css("display") === "none") { - const prevChild = lastChild.prev(); - - shouldMoveMarker = - prevChild.hasClass("unread-marker") || - (prevChild.hasClass("date-marker") && prevChild.prev().hasClass("unread-marker")); - } - } - - if (shouldMoveMarker) { - container - .find(".unread-marker") - .data("unread-id", 0) - .appendTo(container); + if (data.msg.self) { + channel.channel.firstUnread = 0; } let messageLimit = 0; diff --git a/client/js/socket-events/open.js b/client/js/socket-events/open.js index 752a53cf..8064a688 100644 --- a/client/js/socket-events/open.js +++ b/client/js/socket-events/open.js @@ -22,14 +22,8 @@ socket.on("open", function(id) { if (channel) { channel.channel.highlight = 0; channel.channel.unread = 0; + channel.channel.firstUnread = channel.channel.messages[channel.channel.messages.length - 1].id; } utils.updateTitle(); - - // Move unread marker to the bottom - const channelContainer = $("#chat #chan-" + id); - channelContainer - .find(".unread-marker") - .data("unread-id", 0) - .appendTo(channelContainer.find(".messages")); });