Some fixes for unread marker

This commit is contained in:
Pavel Djundik 2018-07-10 11:06:08 +03:00 committed by Pavel Djundik
parent f9967a92c7
commit aa1446c19d
4 changed files with 8 additions and 37 deletions

View File

@ -104,13 +104,7 @@ export default {
return (new Date(previousTime.time)).getDay() !== (new Date(currentTime.time)).getDay(); return (new Date(previousTime.time)).getDay() !== (new Date(currentTime.time)).getDay();
}, },
shouldDisplayUnreadMarker(msgId) { shouldDisplayUnreadMarker(msgId) {
if (this.channel.firstUnread < msgId) { return this.channel.firstUnread === msgId;
return false;
}
this.channel.firstUnread = 0;
return true;
}, },
onCopy() { onCopy() {
clipboard(this.$el); clipboard(this.$el);

View File

@ -126,6 +126,10 @@ window.vueMounted = () => {
const inSidebar = self.parents("#sidebar, #footer").length > 0; const inSidebar = self.parents("#sidebar, #footer").length > 0;
let channel; let channel;
if (vueApp.activeChannel) {
vueApp.activeChannel.channel.firstUnread = vueApp.activeChannel.channel.messages[vueApp.activeChannel.channel.messages.length - 1].id;
}
if (inSidebar) { if (inSidebar) {
channel = findChannel(Number(self.attr("data-id"))); channel = findChannel(Number(self.attr("data-id")));

View File

@ -64,29 +64,8 @@ function processReceivedMessage(data) {
notifyMessage(targetId, channelContainer, data); notifyMessage(targetId, channelContainer, data);
let shouldMoveMarker = data.msg.self; if (data.msg.self) {
channel.channel.firstUnread = 0;
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);
} }
let messageLimit = 0; let messageLimit = 0;

View File

@ -22,14 +22,8 @@ socket.on("open", function(id) {
if (channel) { if (channel) {
channel.channel.highlight = 0; channel.channel.highlight = 0;
channel.channel.unread = 0; channel.channel.unread = 0;
channel.channel.firstUnread = channel.channel.messages[channel.channel.messages.length - 1].id;
} }
utils.updateTitle(); 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"));
}); });