Skip to content

Commit

Permalink
Fix messages appearing as 'continued' after an ignored message (#365)
Browse files Browse the repository at this point in the history
* fix: dont tag events (pins, donos, etc)

* fix: msgs shown as continued after ignored ones

* refactor: move continue check into updateMessages instead

* fix: forgot to change some things after moving the check

* refactor: move `is msg continued` logic into its own function
  • Loading branch information
vyneer authored Dec 27, 2023
1 parent a5d5268 commit c4a9c6d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
6 changes: 1 addition & 5 deletions assets/chat/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,11 +757,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.user.username === message.user.username;
message.continued = win.isContinued(message);
// set highlighted state
message.highlighted = this.shouldHighlightMessage(message);
}
Expand Down
11 changes: 11 additions & 0 deletions assets/chat/js/messages/ChatMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,15 @@ export default class ChatMessage extends ChatUIMessage {
user.equalWatching(this.watching),
);
}

/**
* @param {boolean} isContinued
*/
setContinued(isContinued) {
this.ui.classList.toggle('msg-continue', isContinued);
const ctrl = this.ui.querySelector('.ctrl');
if (ctrl) ctrl.textContent = isContinued ? '' : ': ';

this.continued = isContinued;
}
}
22 changes: 20 additions & 2 deletions assets/chat/js/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class ChatWindow extends EventEmitter {
* this window.
*/
updateMessages(chat) {
for (const message of this.messages) {
for (const [i, message] of this.messages.entries()) {
if (message.type !== MessageTypes.UI) {
message.updateTimeFormat();
}
Expand All @@ -133,7 +133,10 @@ class ChatWindow extends EventEmitter {
message.setOwnMessage(username === chat.user.username);
message.ignore(chat.ignored(username, message.message));
message.highlight(chat.shouldHighlightMessage(message));
message.setTag(chat.taggednicks.get(username));
if (message.type === MessageTypes.USER) {
message.setContinued(this.isContinued(message, this.messages[i - 1]));
message.setTag(chat.taggednicks.get(username));
}
message.setTagTitle(chat.taggednotes.get(username));
message.setWatching(chat.user);

Expand All @@ -149,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);
}

Expand Down

0 comments on commit c4a9c6d

Please sign in to comment.