Skip to content

A platform for community discussion. Free, open, simple.

UX: resets active message when scrolling (#21305)

Joffrey JAFFEUX69a72015f089
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel.js b/plugins/chat/assets/javascripts/discourse/components/chat-channel.js
index dac1c885356..83097137dbe 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-channel.js
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel.js
@@ -504,6 +504,8 @@ export default class ChatLivePane extends Component {
return;
}
+ this.chat.activeMessage = null;
+
if (this.#isAtTop()) {
this.fetchMoreMessages({ direction: PAST });
this.onScrollEnded();
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-message.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-message.hbs
index 02e6edc52ad..53a5baab681 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-message.hbs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-message.hbs
@@ -15,6 +15,7 @@
{{on "touchend" this.handleTouchEnd passive=true}}
{{on "mouseenter" this.onMouseEnter}}
{{on "mouseleave" this.onMouseLeave}}
+ {{on "mousemove" this.onMouseMove}}
class={{concat-class
"chat-message-container"
(if this.pane.selectingMessages "selecting-messages")
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-message.js b/plugins/chat/assets/javascripts/discourse/components/chat-message.js
index 460fae13aa1..4d86113e891 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-message.js
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-message.js
@@ -127,15 +127,30 @@ export default class ChatMessage extends Component {
return;
}
- this._onHoverMessageDebouncedHandler = discourseDebounce(
+ this._onMouseEnterMessageDebouncedHandler = discourseDebounce(
this,
this._debouncedOnHoverMessage,
250
);
}
+ @action
+ onMouseMove() {
+ if (this.site.mobileView) {
+ return;
+ }
+
+ if (this.chat.activeMessage?.model?.id === this.args.message.id) {
+ return;
+ }
+
+ this._setActiveMessage();
+ }
+
@action
onMouseLeave(event) {
+ cancel(this._onMouseEnterMessageDebouncedHandler);
+
if (this.site.mobileView) {
return;
}
@@ -148,20 +163,21 @@ export default class ChatMessage extends Component {
return;
}
- cancel(this._onHoverMessageDebouncedHandler);
-
this.chat.activeMessage = null;
}
@bind
_debouncedOnHoverMessage() {
- if (!this.chat.userCanInteractWithChat) {
- return;
- }
this._setActiveMessage();
}
_setActiveMessage() {
+ cancel(this._onMouseEnterMessageDebouncedHandler);
+
+ if (!this.chat.userCanInteractWithChat) {
+ return;
+ }
+
this.chat.activeMessage = {
model: this.args.message,
context: this.args.context,
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-thread.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-thread.hbs
index 43f265938ad..e2bae197268 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-thread.hbs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-thread.hbs
@@ -26,6 +26,7 @@
<div
class="chat-thread__body popper-viewport"
{{did-insert this.setScrollable}}
+ {{on "scroll" this.resetActiveMessage passive=true}}
>
<div
class="chat-thread__messages chat-messages-container"
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-thread.js b/plugins/chat/assets/javascripts/discourse/components/chat-thread.js
index ab7f5c5c4e6..90993d746eb 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-thread.js
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-thread.js
@@ -193,6 +193,11 @@ export default class ChatThreadPanel extends Component {
this.chatChannelThreadComposer.reset(this.channel);
}
+ @action
+ resetActiveMessage() {
+ this.chat.activeMessage = null;
+ }
+
#sendNewMessage(message) {
// TODO (martin) For desktop notifications
// resetIdle()
diff --git a/plugins/chat/spec/system/chat_channel_spec.rb b/plugins/chat/spec/system/chat_channel_spec.rb
index 970ad56bf30..1a5c31c5d2d 100644
--- a/plugins/chat/spec/system/chat_channel_spec.rb
+++ b/plugins/chat/spec/system/chat_channel_spec.rb
@@ -250,4 +250,28 @@ RSpec.describe "Chat channel", type: :system, js: true do
expect(page).to have_selector("code.lang-ruby")
end
end
+
+ context "when scrolling" do
+ before do
+ channel_1.add(current_user)
+ 50.times { Fabricate(:chat_message, chat_channel: channel_1) }
+ sign_in(current_user)
+ end
+
+ it "resets the active message" do
+ chat.visit_channel(channel_1)
+ last_message = find(".chat-message-container:last-child")
+ last_message.hover
+
+ expect(page).to have_css(
+ ".chat-message-actions-container[data-id='#{last_message["data-id"]}']",
+ )
+
+ find(".chat-messages-scroll").scroll_to(0, -1000)
+
+ expect(page).to have_no_css(
+ ".chat-message-actions-container[data-id='#{last_message["data-id"]}']",
+ )
+ end
+ end
end