Skip to content

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

FIX: add desktop redirect for mobile only chat routes (#25561)

David Battersby4b859754907f
diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat-channels.js b/plugins/chat/assets/javascripts/discourse/routes/chat-channels.js
index 2dfcae3be33..160294e8777 100644
--- a/plugins/chat/assets/javascripts/discourse/routes/chat-channels.js
+++ b/plugins/chat/assets/javascripts/discourse/routes/chat-channels.js
@@ -9,6 +9,12 @@ export default class ChatChannelsRoute extends DiscourseRoute {
this.chat.activeChannel = null;
}
+ beforeModel() {
+ if (this.site.desktopView) {
+ this.router.transitionTo("chat");
+ }
+ }
+
model() {
return this.chatChannelsManager.publicMessageChannels;
}
diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat-direct-messages.js b/plugins/chat/assets/javascripts/discourse/routes/chat-direct-messages.js
index 79b3aa0d2cb..a155266b2b4 100644
--- a/plugins/chat/assets/javascripts/discourse/routes/chat-direct-messages.js
+++ b/plugins/chat/assets/javascripts/discourse/routes/chat-direct-messages.js
@@ -9,6 +9,12 @@ export default class ChatDirectMessagesRoute extends DiscourseRoute {
this.chat.activeChannel = null;
}
+ beforeModel() {
+ if (this.site.desktopView) {
+ this.router.transitionTo("chat");
+ }
+ }
+
model() {
return this.chatChannelsManager.directMessageChannels;
}
diff --git a/plugins/chat/spec/system/navigation_spec.rb b/plugins/chat/spec/system/navigation_spec.rb
index 166198a6bf6..18df73e20c1 100644
--- a/plugins/chat/spec/system/navigation_spec.rb
+++ b/plugins/chat/spec/system/navigation_spec.rb
@@ -88,6 +88,24 @@ RSpec.describe "Navigation", type: :system do
end
end
+ context "when visiting mobile only routes on desktop" do
+ it "redirects /chat/channels to ideal first channel" do
+ visit("/chat/channels")
+
+ expect(page).to have_current_path(
+ chat.channel_path(category_channel.slug, category_channel.id),
+ )
+ end
+
+ it "redirects /chat/direct-messages to ideal first channel" do
+ visit("/chat/direct-messages")
+
+ expect(page).to have_current_path(
+ chat.channel_path(category_channel.slug, category_channel.id),
+ )
+ end
+ end
+
context "when opening chat" do
it "opens the drawer by default" do
visit("/")