diff --git a/client/js/socket-events/msg.js b/client/js/socket-events/msg.js index bbc94cca..3c9b7721 100644 --- a/client/js/socket-events/msg.js +++ b/client/js/socket-events/msg.js @@ -47,7 +47,7 @@ socket.on("msg", function(data) { channel.messages.push(data.msg); if (data.msg.self) { - channel.firstUnread = channel.messages[channel.messages.length - 1].id; + channel.firstUnread = data.msg.id; } else { notifyMessage(targetId, channel, vueApp.activeChannel, data.msg); } diff --git a/client/js/socket-events/open.js b/client/js/socket-events/open.js index 4dcb4aae..428a3d28 100644 --- a/client/js/socket-events/open.js +++ b/client/js/socket-events/open.js @@ -21,7 +21,10 @@ socket.on("open", function(id) { if (channel) { channel.channel.highlight = 0; channel.channel.unread = 0; - channel.channel.firstUnread = channel.channel.messages[channel.channel.messages.length - 1].id; + + if (channel.channel.messages.length > 0) { + channel.channel.firstUnread = channel.channel.messages[channel.channel.messages.length - 1].id; + } } utils.updateTitle(); diff --git a/src/client.js b/src/client.js index 678f11a8..a909e9e8 100644 --- a/src/client.js +++ b/src/client.js @@ -422,10 +422,13 @@ Client.prototype.open = function(socketId, target) { return; } - target.chan.firstUnread = 0; target.chan.unread = 0; target.chan.highlight = 0; + if (target.chan.messages.length > 0) { + target.chan.firstUnread = target.chan.messages[target.chan.messages.length - 1].id; + } + attachedClient.openChannel = target.chan.id; this.lastActiveChannel = target.chan.id; diff --git a/src/models/chan.js b/src/models/chan.js index 74ce1895..2a9f4bda 100644 --- a/src/models/chan.js +++ b/src/models/chan.js @@ -59,7 +59,7 @@ Chan.prototype.pushMessage = function(client, msg, increasesUnread) { if (msg.self) { // reset counters/markers when receiving self-/echo-message this.unread = 0; - this.firstUnread = 0; + this.firstUnread = msg.id; this.highlight = 0; } else if (!isOpen) { if (!this.firstUnread) {