Skip to content

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

UX: disable arrow up to edit if last message is not editable (#20729)

Joffrey JAFFEUXaeab38aff163
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js b/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js
index 09f9210cd5c..731cb85f4d5 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js
@@ -896,16 +896,19 @@ export default class ChatLivePane extends Component {
@action
editLastMessageRequested() {
const lastUserMessage = this.args.channel.messages.findLast(
- (message) =>
- message.user.id === this.currentUser.id &&
- !message.staged &&
- !message.error
+ (message) => message.user.id === this.currentUser.id
);
- if (lastUserMessage) {
- this.editingMessage = lastUserMessage;
- this._focusComposer();
+ if (!lastUserMessage) {
+ return;
}
+
+ if (lastUserMessage.staged || lastUserMessage.error) {
+ return;
+ }
+
+ this.editingMessage = lastUserMessage;
+ this._focusComposer();
}
@action
diff --git a/plugins/chat/spec/system/shortcuts/chat_composer_spec.rb b/plugins/chat/spec/system/shortcuts/chat_composer_spec.rb
index a7dd347750e..be1d9098994 100644
--- a/plugins/chat/spec/system/shortcuts/chat_composer_spec.rb
+++ b/plugins/chat/spec/system/shortcuts/chat_composer_spec.rb
@@ -70,5 +70,19 @@ RSpec.describe "Shortcuts | chat composer", type: :system, js: true do
expect(page.find(".chat-composer-message-details")).to have_content(message_1.message)
end
+
+ context "when last message is not editable" do
+ after { page.driver.browser.network_conditions = { offline: false } }
+
+ it "does not edit a message" do
+ chat.visit_channel(channel_1)
+ page.driver.browser.network_conditions = { offline: true }
+ channel_page.send_message("Hello world")
+
+ find(".chat-composer-input").send_keys(:arrow_up)
+
+ expect(page).to have_no_css(".chat-composer-message-details")
+ end
+ end
end
end