From 08ee28e99bb90047c6881196b5ef1f513386e85c Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 1 Oct 2017 11:52:34 +0300 Subject: [PATCH] Synchornize unread marker when other client opens a channel Fixes #863 --- client/js/socket-events/open.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/client/js/socket-events/open.js b/client/js/socket-events/open.js index 8ed8ed3e..0fd956b1 100644 --- a/client/js/socket-events/open.js +++ b/client/js/socket-events/open.js @@ -3,9 +3,27 @@ const $ = require("jquery"); const socket = require("../socket"); +// Sync unread badge and marker when other clients open a channel socket.on("open", function(id) { - // Another client opened the channel, clear the unread counter + if (id < 1) { + return; + } + + const channel = $("#chat #chan-" + id); + + // Don't do anything if the channel is active on this client + if (channel.length === 0 || channel.hasClass("active")) { + return; + } + + // Clear the unread badge $("#sidebar").find(".chan[data-id='" + id + "'] .badge") .removeClass("highlight") .empty(); + + // Move unread marker to the bottom + channel + .find(".unread-marker") + .data("unread-id", 0) + .appendTo(channel.find(".messages")); });