diff --git a/client/js/lounge.js b/client/js/lounge.js
index 7283728f..c0facbd6 100644
--- a/client/js/lounge.js
+++ b/client/js/lounge.js
@@ -188,6 +188,7 @@ $(function() {
self.addClass("active")
.attr("aria-selected", true)
.find(".badge")
+ .attr("data-highlight", 0)
.removeClass("highlight")
.empty();
diff --git a/client/js/socket-events/msg.js b/client/js/socket-events/msg.js
index f96e139d..8fc68462 100644
--- a/client/js/socket-events/msg.js
+++ b/client/js/socket-events/msg.js
@@ -129,7 +129,9 @@ function processReceivedMessage(data) {
}
function notifyMessage(targetId, channel, msg) {
- const unread = msg.unread;
+ const serverUnread = msg.unread;
+ const serverHighlight = msg.highlight;
+
msg = msg.msg;
if (msg.self) {
@@ -205,13 +207,15 @@ function notifyMessage(targetId, channel, msg) {
}
}
- if (!unread || button.hasClass("active")) {
+ if (!serverUnread || button.hasClass("active")) {
return;
}
- const badge = button.find(".badge").html(helpers_roundBadgeNumber(unread));
+ const badge = button.find(".badge").html(helpers_roundBadgeNumber(serverUnread));
if (msg.highlight) {
- badge.addClass("highlight");
+ badge
+ .attr("data-highlight", serverHighlight)
+ .addClass("highlight");
}
}
diff --git a/client/js/socket-events/open.js b/client/js/socket-events/open.js
index 0fd956b1..07368158 100644
--- a/client/js/socket-events/open.js
+++ b/client/js/socket-events/open.js
@@ -18,6 +18,7 @@ socket.on("open", function(id) {
// Clear the unread badge
$("#sidebar").find(".chan[data-id='" + id + "'] .badge")
+ .attr("data-highlight", 0)
.removeClass("highlight")
.empty();
diff --git a/client/views/chan.tpl b/client/views/chan.tpl
index 93bc5712..d9227d45 100644
--- a/client/views/chan.tpl
+++ b/client/views/chan.tpl
@@ -20,7 +20,7 @@
- {{#if unread}}{{roundBadgeNumber unread}}{{/if}}
+ {{#if unread}}{{roundBadgeNumber unread}}{{/if}}
@@ -28,7 +28,7 @@
{{/equal}}
{{#notEqual type "lobby"}}
{{name}}
- {{#if unread}}{{roundBadgeNumber unread}}{{/if}}
+ {{#if unread}}{{roundBadgeNumber unread}}{{/if}}
diff --git a/src/models/chan.js b/src/models/chan.js
index 45f1661e..3cd7e99b 100644
--- a/src/models/chan.js
+++ b/src/models/chan.js
@@ -48,8 +48,23 @@ Chan.prototype.pushMessage = function(client, msg, increasesUnread) {
// If this channel is open in any of the clients, do not increase unread counter
const isOpen = _.find(client.attachedClients, {openChannel: chan}) !== undefined;
- if ((increasesUnread || msg.highlight) && !isOpen) {
- obj.unread = ++this.unread;
+ if (msg.self) {
+ // reset counters/markers when receiving self-/echo-message
+ this.unread = 0;
+ this.firstUnread = 0;
+ this.highlight = 0;
+ } else if (!isOpen) {
+ if (!this.firstUnread) {
+ this.firstUnread = msg.id;
+ }
+
+ if (increasesUnread || msg.highlight) {
+ obj.unread = ++this.unread;
+ }
+
+ if (msg.highlight) {
+ obj.highlight = ++this.highlight;
+ }
}
client.emit("msg", obj);
@@ -71,20 +86,6 @@ Chan.prototype.pushMessage = function(client, msg, increasesUnread) {
this.dereferencePreviews(deleted);
}
}
-
- 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;
- }
-
- if (msg.highlight) {
- this.highlight++;
- }
- }
};
Chan.prototype.dereferencePreviews = function(messages) {