diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index b629511a..48074f86 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -756,12 +756,7 @@ class Chat { // Populate highlight for this $message if (message.type === MessageTypes.USER) { // check if the last message was from the same user - message.continued = - win.lastmessage && - !win.lastmessage.target && - win.lastmessage.user && - (!win.lastmessage.ignored || win.lastmessage.continued) && // messages should not appear as "continued" if the previous message is ignored and was the start of the thread - win.lastmessage.user.username === message.user.username; + message.continued = win.isContinued(message); // set highlighted state message.highlighted = this.shouldHighlightMessage(message); } diff --git a/assets/chat/js/window.js b/assets/chat/js/window.js index 8fb0e2f9..bbcc60f4 100644 --- a/assets/chat/js/window.js +++ b/assets/chat/js/window.js @@ -134,15 +134,7 @@ class ChatWindow extends EventEmitter { message.ignore(chat.ignored(username, message.message)); message.highlight(chat.shouldHighlightMessage(message)); if (message.type === MessageTypes.USER) { - const lastMessage = this.messages[i - 1]; - message.setContinued( - lastMessage && - !lastMessage.target && - lastMessage.user && - (!lastMessage.ignored || lastMessage.continued) && // messages should not appear as "continued" if the previous message is ignored and was the start of the thread - lastMessage.user.username === username, - ); - + message.setContinued(this.isContinued(message, this.messages[i - 1])); message.setTag(chat.taggednicks.get(username)); } message.setTagTitle(chat.taggednotes.get(username)); @@ -160,6 +152,21 @@ class ChatWindow extends EventEmitter { this.messages = this.messages.filter((m) => m !== this.lastmessage); } + /** + * @param {ChatMessage} message + * @param {ChatMessage} lastMessage + * @returns {boolean} + */ + isContinued(message, lastMessage = this.lastmessage) { + return ( + lastMessage && + !lastMessage.target && + lastMessage.user && + (!lastMessage.ignored || lastMessage.continued) && // messages should not appear as "continued" if the previous message is ignored and was the start of the thread + lastMessage.user.username === message.user.username + ); + } + cleanupThrottle = throttle(50, this.cleanup); }