Skip to content

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

FIX: handles starting draft dm from sidebar (#18946)

Joffrey JAFFEUX074aa5eb5e54
diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat.js b/plugins/chat/assets/javascripts/discourse/routes/chat.js
index 4d072303213..863d5d7fc1a 100644
--- a/plugins/chat/assets/javascripts/discourse/routes/chat.js
+++ b/plugins/chat/assets/javascripts/discourse/routes/chat.js
@@ -4,6 +4,7 @@ import { defaultHomepage } from "discourse/lib/utilities";
import { inject as service } from "@ember/service";
import { scrollTop } from "discourse/mixins/scroll-top";
import { schedule } from "@ember/runloop";
+import { DRAFT_CHANNEL_VIEW } from "discourse/plugins/chat/discourse/services/chat";
export default class ChatRoute extends DiscourseRoute {
@service chat;
@@ -18,14 +19,21 @@ export default class ChatRoute extends DiscourseRoute {
beforeModel(transition) {
if (
transition.from && // don't intercept when directly loading chat
- this.chatPreferredMode.isDrawer &&
- transition.intent?.name === "chat.channel" // sidebar can only load a channel
+ this.chatPreferredMode.isDrawer
) {
- transition.abort();
- const id = transition.intent.contexts[0];
- return this.chat.getChannelBy("id", id).then((channel) => {
- this.appEvents.trigger("chat:open-channel", channel);
- });
+ if (transition.intent?.name === "chat.channel") {
+ transition.abort();
+ const id = transition.intent.contexts[0];
+ return this.chat.getChannelBy("id", id).then((channel) => {
+ this.appEvents.trigger("chat:open-channel", channel);
+ });
+ }
+
+ if (transition.intent?.name === "chat.draft-channel") {
+ transition.abort();
+ this.appEvents.trigger("chat:open-view", DRAFT_CHANNEL_VIEW);
+ return;
+ }
}
if (!this.chat.userCanChat) {
diff --git a/plugins/chat/spec/system/navigation_spec.rb b/plugins/chat/spec/system/navigation_spec.rb
index 12ca87100d1..5438cebc7d4 100644
--- a/plugins/chat/spec/system/navigation_spec.rb
+++ b/plugins/chat/spec/system/navigation_spec.rb
@@ -8,6 +8,7 @@ RSpec.describe "Navigation", type: :system, js: true do
fab!(:category_channel) { Fabricate(:category_channel) }
fab!(:message) { Fabricate(:chat_message, chat_channel: category_channel) }
let(:chat_page) { PageObjects::Pages::Chat.new }
+ let(:sidebar_page) { PageObjects::Pages::Sidebar.new }
before do
# ensures we have one valid registered admin
@@ -125,5 +126,28 @@ RSpec.describe "Navigation", type: :system, js: true do
)
end
end
+
+ context "when starting draft from sidebar with drawer preferred" do
+ it "opens draft in drawer" do
+ visit("/")
+ sidebar_page.start_draft_dm
+
+ expect(page).to have_current_path("/")
+ expect(page).to have_css(".topic-chat-container.expanded.visible")
+ end
+ end
+
+ context "when starting draft from sidebar with full page preferred" do
+ it "opens draft in full page" do
+ visit("/")
+ chat_page.open_from_header
+ chat_page.maximize_drawer
+ visit("/")
+ sidebar_page.start_draft_dm
+
+ expect(page).to have_current_path("/chat/draft-channel")
+ expect(page).not_to have_css(".topic-chat-container.expanded.visible")
+ end
+ end
end
end
diff --git a/plugins/chat/spec/system/page_objects/sidebar/sidebar.rb b/plugins/chat/spec/system/page_objects/sidebar/sidebar.rb
new file mode 100644
index 00000000000..b9633001c20
--- /dev/null
+++ b/plugins/chat/spec/system/page_objects/sidebar/sidebar.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Pages
+ class Sidebar < PageObjects::Pages::Base
+ def start_draft_dm
+ find(".sidebar-section-chat-dms .sidebar-section-header-button", visible: false).click
+ end
+ end
+ end
+end
diff --git a/plugins/chat/test/javascripts/acceptance/core-sidebar-test.js b/plugins/chat/test/javascripts/acceptance/core-sidebar-test.js
index ea2a709feae..4cf7fa9726e 100644
--- a/plugins/chat/test/javascripts/acceptance/core-sidebar-test.js
+++ b/plugins/chat/test/javascripts/acceptance/core-sidebar-test.js
@@ -5,14 +5,7 @@ import {
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
-import {
- click,
- currentURL,
- fillIn,
- settled,
- triggerKeyEvent,
- visit,
-} from "@ember/test-helpers";
+import { click, currentURL, settled, visit } from "@ember/test-helpers";
import { directMessageChannels } from "discourse/plugins/chat/chat-fixtures";
import { cloneJSON } from "discourse-common/lib/object";
import I18n from "I18n";
@@ -421,13 +414,11 @@ acceptance("Discourse Chat - Core Sidebar", function (needs) {
test("Open a new direct conversation", async function (assert) {
await visit("/");
-
await click(".sidebar-section-chat-dms .sidebar-section-header-button");
- assert.ok(exists(".direct-message-creator"));
- await fillIn(".filter-usernames", "hawk");
- await triggerKeyEvent(".filter-usernames", "keydown", "Enter");
- assert.strictEqual(currentURL(), "/chat/draft-channel");
+ assert.ok(exists(".direct-message-creator"));
+ assert.ok(exists(".topic-chat-container.expanded.visible"));
+ assert.strictEqual(currentURL(), "/");
});
test("Escapes public channel titles", async function (assert) {