Synchronize unread marker when client reconnects

Fixes #1571
This commit is contained in:
Pavel Djundik 2017-10-01 12:00:59 +03:00
parent 0cc9c4166b
commit 38584e2f8e

View File

@ -125,13 +125,15 @@ function renderChannelMessages(data) {
const documentFragment = buildChannelMessages($(document.createDocumentFragment()), data.id, data.type, data.messages); const documentFragment = buildChannelMessages($(document.createDocumentFragment()), data.id, data.type, data.messages);
const channel = chat.find("#chan-" + data.id + " .messages").append(documentFragment); const channel = chat.find("#chan-" + data.id + " .messages").append(documentFragment);
const template = $(templates.unread_marker()); renderUnreadMarker($(templates.unread_marker()), data.firstUnread, channel);
}
if (data.firstUnread > 0) { function renderUnreadMarker(template, firstUnread, channel) {
let first = channel.find("#msg-" + data.firstUnread); if (firstUnread > 0) {
let first = channel.find("#msg-" + firstUnread);
if (!first.length) { if (!first.length) {
template.data("unread-id", data.firstUnread); template.data("unread-id", firstUnread);
channel.prepend(template); channel.prepend(template);
} else { } else {
const parent = first.parent(); const parent = first.parent();
@ -201,6 +203,9 @@ function renderNetworks(data, singleNetwork) {
const container = chan.find(".messages"); const container = chan.find(".messages");
buildChannelMessages(container, channel.id, channel.type, channel.messages); buildChannelMessages(container, channel.id, channel.type, channel.messages);
const unreadMarker = container.find(".unread-marker").data("unread-id", 0);
renderUnreadMarker(unreadMarker, channel.firstUnread, container);
if (container.find(".msg").length >= 100) { if (container.find(".msg").length >= 100) {
container.find(".show-more").addClass("show"); container.find(".show-more").addClass("show");
} }