Skip to content

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

DEV: revert long press changes (#32668)

Joffrey JAFFEUX52b79012e977
diff --git a/plugins/chat/assets/javascripts/discourse/modifiers/chat/on-long-press.js b/plugins/chat/assets/javascripts/discourse/modifiers/chat/on-long-press.js
index 51c0a8130fe..e1389ebaa16 100644
--- a/plugins/chat/assets/javascripts/discourse/modifiers/chat/on-long-press.js
+++ b/plugins/chat/assets/javascripts/discourse/modifiers/chat/on-long-press.js
@@ -32,7 +32,9 @@ export default class ChatOnLongPress extends Modifier {
this.onLongPressEnd = onLongPressEnd || (() => {});
this.onLongPressCancel = onLongPressCancel || (() => {});
- this.element.addEventListener("pointerdown", this.handlePointerDown);
+ this.element.addEventListener("touchstart", this.handleTouchStart, {
+ passive: true,
+ });
}
@bind
@@ -40,36 +42,36 @@ export default class ChatOnLongPress extends Modifier {
cancel(this.timeout);
if (this.capabilities.touch) {
- this.element.removeEventListener("pointermove", this.onCancel);
- this.element.removeEventListener("pointerup", this.onCancel);
- this.element.removeEventListener("pointercancel", this.onCancel);
+ this.element.removeEventListener("touchmove", this.onCancel, {
+ passive: true,
+ });
+ this.element.removeEventListener("touchend", this.onCancel);
+ this.element.removeEventListener("touchcancel", this.onCancel);
}
this.onLongPressCancel(this.element);
}
@bind
- handlePointerDown(event) {
- // Handle multi-touch
- if (event.isPrimary === false) {
+ handleTouchStart(event) {
+ if (event.touches.length > 1) {
this.onCancel();
return;
}
-
this.onLongPressStart(this.element, event);
-
- this.element.addEventListener("pointermove", this.onCancel);
- this.element.addEventListener("pointerup", this.onCancel);
- this.element.addEventListener("pointercancel", this.onCancel);
-
+ this.element.addEventListener("touchmove", this.onCancel, {
+ passive: true,
+ });
+ this.element.addEventListener("touchend", this.onCancel);
+ this.element.addEventListener("touchcancel", this.onCancel);
this.timeout = discourseLater(() => {
if (this.isDestroying || this.isDestroyed) {
return;
}
- // Add one-time event handler to prevent default action
- this.element.addEventListener("pointerup", cancelEvent, {
+ this.element.addEventListener("touchend", cancelEvent, {
once: true,
+ passive: true,
});
this.onLongPressEnd(this.element, event);
@@ -81,8 +83,9 @@ export default class ChatOnLongPress extends Modifier {
return;
}
- // Remove the main pointerdown listener
- this.element.removeEventListener("pointerdown", this.handlePointerDown);
+ this.element.removeEventListener("touchstart", this.handleTouchStart, {
+ passive: true,
+ });
this.onCancel();
}
diff --git a/plugins/chat/spec/system/page_objects/chat/chat_channel.rb b/plugins/chat/spec/system/page_objects/chat/chat_channel.rb
index 6a13269494e..a87da09618c 100644
--- a/plugins/chat/spec/system/page_objects/chat/chat_channel.rb
+++ b/plugins/chat/spec/system/page_objects/chat/chat_channel.rb
@@ -74,20 +74,15 @@ module PageObjects
message_by_id(message.id).find(".chat-message-expand").click
end
+ def emoji(message, code)
+ messages.emoji(message, code)
+ end
+
def expand_message_actions(message)
hover_message(message)
click_more_button
end
- def expand_message_actions_mobile(message, delay: 2)
- find(message_by_id_selector(message.id)).find(".chat-message-content").click(delay: delay)
- end
-
- def click_message_action_mobile(message, message_action)
- expand_message_actions_mobile(message, delay: 0.4)
- find(".chat-message-actions [data-id=\"#{message_action}\"]").click
- end
-
def hover_message(message)
message = message_by_id(message.id)
# Scroll to top of message so that the actions are not hidden
@@ -107,15 +102,7 @@ module PageObjects
end
def bookmark_message(message)
- messages.has_message?(id: message.id)
-
- if page.has_css?("html.mobile-view", wait: 0)
- click_message_action_mobile(message, "bookmark")
- expect(page).to have_css(".d-modal:not(.is-animating)")
- else
- hover_message(message)
- find(".bookmark-btn").click
- end
+ messages.bookmark(message)
end
def click_more_button
@@ -140,7 +127,7 @@ module PageObjects
messages.has_message?(id: message.id)
if page.has_css?("html.mobile-view", wait: 0)
- click_message_action_mobile(message, "reply")
+ messages.reply_to(message)
else
hover_message(message)
find(".reply-btn").click
diff --git a/plugins/chat/spec/system/page_objects/chat/components/message.rb b/plugins/chat/spec/system/page_objects/chat/components/message.rb
index 29e1ec64930..83e1636826c 100644
--- a/plugins/chat/spec/system/page_objects/chat/components/message.rb
+++ b/plugins/chat/spec/system/page_objects/chat/components/message.rb
@@ -32,7 +32,7 @@ module PageObjects
def secondary_action(action)
if page.has_css?("html.mobile-view", wait: 0)
- component.find(".chat-message-text").click(delay: 0.6)
+ open_mobile_actions
page.find(".chat-message-actions [data-id=\"#{action}\"]").click
else
open_more_menu
@@ -40,6 +40,48 @@ module PageObjects
end
end
+ def open_mobile_actions
+ page.execute_script(<<-JS, component)
+ arguments[0].dispatchEvent(new TouchEvent("touchstart", {
+ cancelable: true,
+ bubbles: true,
+ touches: [
+ new Touch({ identifier: Date.now(), target: arguments[0] })
+ ],
+ }));
+
+
+ setTimeout(() => {
+ arguments[0].dispatchEvent(new TouchEvent("touchend", {
+ cancelable: true,
+ bubbles: true,
+ touches: [
+ new Touch({ identifier: Date.now(), target: arguments[0] })
+ ],
+ }));
+ }, 600);
+ JS
+ end
+
+ def bookmark
+ if page.has_css?("html.mobile-view", wait: 0)
+ secondary_action("bookmark")
+ else
+ hover
+ page.find(".chat-message-actions .bookmark-btn").click
+ end
+ end
+
+ def emoji(code)
+ if page.has_css?("html.mobile-view", wait: 0)
+ open_mobile_actions
+ else
+ hover
+ end
+
+ page.find(".chat-message-actions [data-emoji-name='#{code}']").click
+ end
+
def select(shift: false)
if component[:class].include?("-selectable")
message_selector = component.find(".chat-message-selector")
diff --git a/plugins/chat/spec/system/page_objects/chat/components/messages.rb b/plugins/chat/spec/system/page_objects/chat/components/messages.rb
index 239bdc77030..df9c9a6b320 100644
--- a/plugins/chat/spec/system/page_objects/chat/components/messages.rb
+++ b/plugins/chat/spec/system/page_objects/chat/components/messages.rb
@@ -20,6 +20,10 @@ module PageObjects
find(message).secondary_action("copyLink")
end
+ def bookmark(message)
+ find(message).bookmark
+ end
+
def copy_text(message)
find(message).secondary_action("copyText")
end
@@ -28,6 +32,14 @@ module PageObjects
find(message).secondary_action("flag")
end
+ def reply_to(message)
+ find(message).secondary_action("reply")
+ end
+
+ def emoji(message, code)
+ find(message).emoji(code)
+ end
+
def delete(message)
find(message).secondary_action("delete")
end
diff --git a/plugins/chat/spec/system/react_to_message_spec.rb b/plugins/chat/spec/system/react_to_message_spec.rb
index bf63afef4c2..be01537501f 100644
--- a/plugins/chat/spec/system/react_to_message_spec.rb
+++ b/plugins/chat/spec/system/react_to_message_spec.rb
@@ -138,8 +138,7 @@ RSpec.describe "React to message", type: :system do
it "adds a reaction" do
sign_in(current_user)
chat.visit_channel(category_channel_1)
- channel.expand_message_actions_mobile(message_1)
- find(".main-actions [data-emoji-name=\"+1\"]").click
+ channel.emoji(message_1, "+1")
expect(channel.message_reactions_list(message_1)).to have_css("[data-emoji-name=\"+1\"]")
end