A platform for community discussion. Free, open, simple.
FIX: default to starred channels only in mobile/drawer modes (#36569)
Régis Hanola3f3d0bff58c
diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat/starred-channels.js b/plugins/chat/assets/javascripts/discourse/routes/chat/starred-channels.jsindex 0cf7a86ee7f..e87cfc1af38 100644--- a/plugins/chat/assets/javascripts/discourse/routes/chat/starred-channels.js+++ b/plugins/chat/assets/javascripts/discourse/routes/chat/starred-channels.js@@ -3,7 +3,6 @@ import DiscourseRoute from "discourse/routes/discourse";export default class ChatStarredChannelsRoute extends DiscourseRoute {@service chat;- @service chatStateManager;@service router;@service site;@@ -12,22 +11,19 @@ export default class ChatStarredChannelsRoute extends DiscourseRoute {}async beforeModel() {- // Redirect on desktop - mobile-only feature+ // Redirect on desktop fullscreen - starred channels are shown in sidebarif (!this.site.mobileView) {const channel = this.chat.activeChannel;- const lastKnownURL = this.chatStateManager.lastKnownChatURL;if (channel) {this.router.replaceWith("chat.channel", ...channel.routeModels);- } else if (lastKnownURL) {- this.router.replaceWith(lastKnownURL);} else {this.router.replaceWith("chat");}return;}- // Load channels before rendering+ // Load channels before rendering (mobile only)await this.chat.loadChannels();}}diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-state-manager.js b/plugins/chat/assets/javascripts/discourse/services/chat-state-manager.jsindex 517acfcc48a..d9416556d26 100644--- a/plugins/chat/assets/javascripts/discourse/services/chat-state-manager.js+++ b/plugins/chat/assets/javascripts/discourse/services/chat-state-manager.js@@ -194,7 +194,12 @@ export default class ChatStateManager extends Service {return this._chatURL;}- if (this.chatChannelsManager.hasStarredChannels) {+ // On mobile or drawer mode, default to starred channels if user has any+ // On desktop fullscreen, starred channels are shown in the sidebar+ if (+ (this.site.mobileView || this.isDrawerPreferred) &&+ this.chatChannelsManager.hasStarredChannels+ ) {return "/chat/starred-channels";}diff --git a/plugins/chat/spec/system/drawer/starred_channels_spec.rb b/plugins/chat/spec/system/drawer/starred_channels_spec.rbindex c81817d61dd..106d411da4b 100644--- a/plugins/chat/spec/system/drawer/starred_channels_spec.rb+++ b/plugins/chat/spec/system/drawer/starred_channels_spec.rb@@ -19,6 +19,13 @@ RSpec.describe "Drawer - starred channels", type: :system docontext "when user has starred channels" dobefore { channel_1.membership_for(current_user).update!(starred: true) }+ it "defaults to starred channels when opening drawer" do+ visit("/")+ chat_page.open_from_header++ expect(drawer_page).to have_open_starred_channels+ end+it "shows starred tab in footer" dovisit("/")chat_page.open_from_headerdiff --git a/plugins/chat/spec/system/starred_channels_spec.rb b/plugins/chat/spec/system/starred_channels_spec.rbindex c5ef6f45a98..20bec52c35b 100644--- a/plugins/chat/spec/system/starred_channels_spec.rb+++ b/plugins/chat/spec/system/starred_channels_spec.rb@@ -346,28 +346,24 @@ RSpec.describe "Starred channels", type: :system docontext "when opening chat without a known last location" dofab!(:channel_1) { Fabricate(:category_channel, name: "Channel A") }- before { channel_1.add(current_user) }-- context "when user has starred channels" do- before { channel_1.membership_for(current_user).update!(starred: true) }+ before do+ channel_1.add(current_user)+ channel_1.membership_for(current_user).update!(starred: true)+ end- it "opens to starred channels" do- visit("/")- chat_page.prefers_full_page- chat_page.open_from_header+ it "defaults to starred channels on mobile", mobile: true do+ visit("/")+ chat_page.open_from_header- expect(page).to have_current_path("/chat/starred-channels")- end+ expect(page).to have_current_path("/chat/starred-channels")end- context "when user has no starred channels" do- it "opens to the default chat index" do- visit("/")- chat_page.prefers_full_page- chat_page.open_from_header+ it "defaults to chat index on desktop fullscreen (starred channels in sidebar)" do+ visit("/")+ chat_page.prefers_full_page+ chat_page.open_from_header- expect(page).to have_current_path("/chat/browse/open")- end+ expect(page).to have_current_path("/chat/browse/open")endenddiff --git a/plugins/chat/test/javascripts/unit/services/chat-state-manager-test.js b/plugins/chat/test/javascripts/unit/services/chat-state-manager-test.jsindex a15c59b1211..1ebd513a041 100644--- a/plugins/chat/test/javascripts/unit/services/chat-state-manager-test.js+++ b/plugins/chat/test/javascripts/unit/services/chat-state-manager-test.js@@ -66,10 +66,29 @@ module(assert.strictEqual(this.subject.lastKnownChatURL, "/chat");this.subject.storeChatURL("/bar");-assert.strictEqual(this.subject.lastKnownChatURL, "/bar");});+ test("lastKnownChatURL defaults to starred channels only in drawer mode", function (assert) {+ const chatChannelsManager = getOwner(this).lookup(+ "service:chat-channels-manager"+ );+ sinon.stub(chatChannelsManager, "hasStarredChannels").get(() => true);++ assert.strictEqual(+ this.subject.lastKnownChatURL,+ "/chat/starred-channels",+ "defaults to starred-channels in drawer mode"+ );++ this.subject.prefersFullPage();+ assert.strictEqual(+ this.subject.lastKnownChatURL,+ "/chat",+ "defaults to /chat in fullscreen mode (starred channels in sidebar)"+ );+ });+test("lastKnownAppURL", function (assert) {assert.strictEqual(this.subject.lastKnownAppURL, "/latest");