diff --git a/client/js/render.js b/client/js/render.js index bb8be296..881c86ff 100644 --- a/client/js/render.js +++ b/client/js/render.js @@ -125,13 +125,15 @@ function renderChannelMessages(data) { const documentFragment = buildChannelMessages($(document.createDocumentFragment()), data.id, data.type, data.messages); 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) { - let first = channel.find("#msg-" + data.firstUnread); +function renderUnreadMarker(template, firstUnread, channel) { + if (firstUnread > 0) { + let first = channel.find("#msg-" + firstUnread); if (!first.length) { - template.data("unread-id", data.firstUnread); + template.data("unread-id", firstUnread); channel.prepend(template); } else { const parent = first.parent(); @@ -201,6 +203,9 @@ function renderNetworks(data, singleNetwork) { const container = chan.find(".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) { container.find(".show-more").addClass("show"); }