From d675297405dce87864296c7ce8f66acf9a97cf8b Mon Sep 17 00:00:00 2001 From: dgw Date: Tue, 17 Oct 2017 07:42:43 -0500 Subject: [PATCH] Mark channels as read when receiving self-messages Resets highlight counter and last unread message ID on server, and clears the badge on the active client when the message is rendered. Resolves #911 --- client/js/socket-events/msg.js | 5 +++++ src/models/chan.js | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/client/js/socket-events/msg.js b/client/js/socket-events/msg.js index a576451f..840fe10b 100644 --- a/client/js/socket-events/msg.js +++ b/client/js/socket-events/msg.js @@ -61,6 +61,11 @@ function processReceivedMessage(data) { .appendTo(container); } + // Clear unread/highlight counter if self-message + if (data.msg.self) { + sidebar.find("[data-target='" + target + "'] .badge").removeClass("highlight").empty(); + } + // Message arrived in a non active channel, trim it to 100 messages if (activeChannelId !== targetId && container.find(".msg").slice(0, -100).remove().length) { channel.find(".show-more").addClass("show"); diff --git a/src/models/chan.js b/src/models/chan.js index efb28738..8dacc682 100644 --- a/src/models/chan.js +++ b/src/models/chan.js @@ -72,7 +72,11 @@ Chan.prototype.pushMessage = function(client, msg, increasesUnread) { } } - if (!msg.self && !isOpen) { + if (msg.self) { + // reset counters/markers when receiving self-/echo-message + this.firstUnread = 0; + this.highlight = 0; + } else if (!isOpen) { if (!this.firstUnread) { this.firstUnread = msg.id; }