Fix unread marker being off by one on the server

This commit is contained in:
Pavel Djundik 2018-07-17 11:41:12 +03:00 committed by Pavel Djundik
parent 0e7880a049
commit c70b4d4c80
4 changed files with 10 additions and 4 deletions

View File

@ -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);
}

View File

@ -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();

View File

@ -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;

View File

@ -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) {