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

Chat mobile has separate routes for channels and direct messages. However on desktop we want to prevent these routes from being accessible as they aren't intended to be used by chat in full-page or drawer mode on desktop.
This commit is contained in:
David Battersby 2024-02-05 13:26:01 +08:00 committed by GitHub
parent ac53e5a962
commit 4b85975490
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 0 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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("/")