diff --git a/client/components/MessageList.vue b/client/components/MessageList.vue index 492792fd..710485bc 100644 --- a/client/components/MessageList.vue +++ b/client/components/MessageList.vue @@ -232,8 +232,16 @@ export default { return; } - let lastMessage = this.channel.messages[0]; - lastMessage = lastMessage ? lastMessage.id : -1; + let lastMessage = -1; + + // Find the id of first message that isn't showInActive + // If showInActive is set, this message is actually in another channel + for (const message of this.channel.messages) { + if (!message.showInActive) { + lastMessage = message.id; + break; + } + } this.channel.historyLoading = true; diff --git a/client/js/socket-events/msg.js b/client/js/socket-events/msg.js index af8d6b05..df5f1010 100644 --- a/client/js/socket-events/msg.js +++ b/client/js/socket-events/msg.js @@ -39,7 +39,13 @@ socket.on("msg", function(data) { ) { channel = vueApp.activeChannel.channel; - data.chan = channel.id; + if (data.chan === channel.id) { + // If active channel is the intended channel for this message, + // remove the showInActive flag + data.msg.showInActive = false; + } else { + data.chan = channel.id; + } } else if (!isActiveChannel) { // Do not set unread counter for channel if it is currently active on this client // It may increase on the server before it processes channel open event from this client diff --git a/src/models/chan.js b/src/models/chan.js index 4a8da52d..1fe411e7 100644 --- a/src/models/chan.js +++ b/src/models/chan.js @@ -84,6 +84,11 @@ Chan.prototype.pushMessage = function(client, msg, increasesUnread) { return; } + // showInActive is only processed on "msg", don't need it on page reload + if (msg.showInActive) { + delete msg.showInActive; + } + this.writeUserLog(client, msg); if (Helper.config.maxHistory >= 0 && this.messages.length > Helper.config.maxHistory) {