A platform for community discussion. Free, open, simple.
FIX: Composer mode was not being remembered on new PM (#33962)
Martin Brennan8763cdb477f7
diff --git a/app/assets/javascripts/discourse/app/components/d-editor.gjs b/app/assets/javascripts/discourse/app/components/d-editor.gjsindex 9fd2603019a..1012a034abe 100644--- a/app/assets/javascripts/discourse/app/components/d-editor.gjs+++ b/app/assets/javascripts/discourse/app/components/d-editor.gjs@@ -94,9 +94,9 @@ export default class DEditor extends Component {this.setupToolbar();- // TODO (martin) Remove this once we are sure all users have migrated- // to the new rich editor preference, or a few months after the 3.5 release.if (this.siteSettings.rich_editor) {+ // TODO (martin) Remove this once we are sure all users have migrated+ // to the new rich editor preference, or a few months after the 3.5 release.await this.handleOldRichEditorPreference();if (this.currentUser.useRichEditor) {diff --git a/app/serializers/user_option_serializer.rb b/app/serializers/user_option_serializer.rbindex 4bdefe81e1c..7e2253e27f5 100644--- a/app/serializers/user_option_serializer.rb+++ b/app/serializers/user_option_serializer.rb@@ -43,7 +43,8 @@ class UserOptionSerializer < ApplicationSerializer:sidebar_link_to_filtered_list,:sidebar_show_count_of_new_items,:watched_precedence_over_muted,- :topics_unread_when_closed+ :topics_unread_when_closed,+ :composition_modedef auto_track_topics_after_msecsobject.auto_track_topics_after_msecs || SiteSetting.default_other_auto_track_topics_after_msecsdiff --git a/spec/requests/api/schemas/json/user_get_response.json b/spec/requests/api/schemas/json/user_get_response.jsonindex 6e2854d2cc4..c2c94d65fe9 100644--- a/spec/requests/api/schemas/json/user_get_response.json+++ b/spec/requests/api/schemas/json/user_get_response.json@@ -815,6 +815,9 @@},"topics_unread_when_closed": {"type": "boolean"+ },+ "composition_mode": {+ "type": "integer"}},"required": [diff --git a/spec/system/composer/prosemirror_editor_spec.rb b/spec/system/composer/prosemirror_editor_spec.rbindex b1f8ecc9603..8caa50bd65f 100644--- a/spec/system/composer/prosemirror_editor_spec.rb+++ b/spec/system/composer/prosemirror_editor_spec.rb@@ -1,7 +1,7 @@# frozen_string_literal: truedescribe "Composer - ProseMirror editor", type: :system do- fab!(:user) do+ fab!(:current_user) doFabricate(:user,refresh_auto_groups: true,@@ -14,7 +14,7 @@ describe "Composer - ProseMirror editor", type: :system dolet(:composer) { PageObjects::Components::Composer.new }let(:rich) { composer.rich_editor }- before { sign_in(user) }+ before { sign_in(current_user) }def open_composerpage.visit "/new-topic"@@ -40,16 +40,29 @@ describe "Composer - ProseMirror editor", type: :system doexpect(composer).to have_composer_preview_toggleend- it "saves the user's rich editor preference to the database" do+ it "saves the user's rich editor preference and remembers it when reopening the composer" doopen_composer+ expect(composer).to have_rich_editor_activecomposer.toggle_rich_editor- expect(page).to have_css(".composer-toggle-switch.--markdown")+ expect(composer).to have_markdown_editor_activetry_until_success(frequency: 0.5) do- expect(user.user_option.reload.composition_mode).to eq(+ expect(current_user.user_option.reload.composition_mode).to eq(UserOption.composition_mode_types[:markdown],)end++ visit("/")+ open_composer+ expect(composer).to have_markdown_editor_active+ end++ it "remembers the user's rich editor preference when starting a new PM" do+ current_user.user_option.update!(composition_mode: UserOption.composition_mode_types[:rich])+ page.visit("/u/#{current_user.username}/messages")+ find(".new-private-message").click+ expect(composer).to be_opened+ expect(composer).to have_rich_editor_activeend# TODO (martin) Remove this once we are sure all users have migrated@@ -68,7 +81,7 @@ describe "Composer - ProseMirror editor", type: :system doexpect(composer).to have_rich_editortry_until_success(frequency: 0.5) do- expect(user.user_option.reload.composition_mode).to eq(+ expect(current_user.user_option.reload.composition_mode).to eq(UserOption.composition_mode_types[:rich],)end@@ -83,7 +96,7 @@ describe "Composer - ProseMirror editor", type: :system docontext "with autocomplete" doit "triggers an autocomplete on mention" doopen_composer- composer.type_content("@#{user.username}")+ composer.type_content("@#{current_user.username}")expect(composer).to have_mention_autocompleteend@@ -939,19 +952,19 @@ describe "Composer - ProseMirror editor", type: :system dobefore doDraft.set(- user,+ current_user,topic.draft_key,0,- { reply: "hey @#{user.username} and @unknown - how are you?" }.to_json,+ { reply: "hey @#{current_user.username} and @unknown - how are you?" }.to_json,)endit "validates manually typed mentions" doopen_composer- composer.type_content("Hey @#{user.username} ")+ composer.type_content("Hey @#{current_user.username} ")- expect(rich).to have_css("a.mention", text: user.username)+ expect(rich).to have_css("a.mention", text: current_user.username)composer.type_content("and @invalid_user - how are you?")@@ -959,7 +972,9 @@ describe "Composer - ProseMirror editor", type: :system docomposer.toggle_rich_editor- expect(composer).to have_value("Hey @#{user.username} and @invalid_user - how are you?")+ expect(composer).to have_value(+ "Hey @#{current_user.username} and @invalid_user - how are you?",+ )endit "validates mentions in drafts" do@@ -967,7 +982,7 @@ describe "Composer - ProseMirror editor", type: :system doexpect(composer).to be_opened- expect(rich).to have_css("a.mention", text: user.username)+ expect(rich).to have_css("a.mention", text: current_user.username)expect(rich).to have_no_css("a.mention", text: "@unknown")enddiff --git a/spec/system/page_objects/components/composer.rb b/spec/system/page_objects/components/composer.rbindex bad738a68d4..5018e8eb712 100644--- a/spec/system/page_objects/components/composer.rb+++ b/spec/system/page_objects/components/composer.rb@@ -329,11 +329,15 @@ module PageObjectsenddef has_rich_editor_active?- find("#{COMPOSER_ID}").has_css?(".composer-toggle-switch__right-icon.--active")+ find("#{COMPOSER_ID}").has_css?(".composer-toggle-switch.--rte")enddef has_no_rich_editor_active?- find("#{COMPOSER_ID}").has_css?(".composer-toggle-switch__left-icon.--active")+ find("#{COMPOSER_ID}").has_css?(".composer-toggle-switch.--markdown")+ end++ def has_markdown_editor_active?+ has_no_rich_editor_active?enddef toggle_rich_editor