Skip to content

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

FIX: redirect to channels list when no starred channels exist (#36575)

Régis Hanol5297478bc68f
diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat/starred-channels.js b/plugins/chat/assets/javascripts/discourse/routes/chat/starred-channels.js
index e87cfc1af38..822fad4af66 100644
--- a/plugins/chat/assets/javascripts/discourse/routes/chat/starred-channels.js
+++ b/plugins/chat/assets/javascripts/discourse/routes/chat/starred-channels.js
@@ -3,6 +3,7 @@ import DiscourseRoute from "discourse/routes/discourse";
export default class ChatStarredChannelsRoute extends DiscourseRoute {
@service chat;
+ @service chatChannelsManager;
@service router;
@service site;
@@ -11,8 +12,7 @@ export default class ChatStarredChannelsRoute extends DiscourseRoute {
}
async beforeModel() {
- // Redirect on desktop fullscreen - starred channels are shown in sidebar
- if (!this.site.mobileView) {
+ if (this.site.desktopView) {
const channel = this.chat.activeChannel;
if (channel) {
@@ -20,10 +20,14 @@ export default class ChatStarredChannelsRoute extends DiscourseRoute {
} else {
this.router.replaceWith("chat");
}
- return;
- }
+ } else {
+ // Load channels before rendering (mobile only)
+ await this.chat.loadChannels();
- // Load channels before rendering (mobile only)
- await this.chat.loadChannels();
+ // If there are no starred channels, redirect to all channels
+ if (!this.chatChannelsManager.hasStarredChannels) {
+ this.router.replaceWith("chat.channels");
+ }
+ }
}
}
diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-drawer-router.js b/plugins/chat/assets/javascripts/discourse/services/chat-drawer-router.js
index f8d198fed5b..b6cbe681ef1 100644
--- a/plugins/chat/assets/javascripts/discourse/services/chat-drawer-router.js
+++ b/plugins/chat/assets/javascripts/discourse/services/chat-drawer-router.js
@@ -160,6 +160,11 @@ const ROUTES = {
},
"chat.starred-channels": {
name: ChatDrawerRoutesStarredChannels,
+ redirect: (context) => {
+ if (!context.chatChannelsManager.hasStarredChannels) {
+ return "/chat/channels";
+ }
+ },
},
"chat.threads": {
name: ChatDrawerRoutesThreads,
diff --git a/plugins/chat/spec/system/drawer/starred_channels_spec.rb b/plugins/chat/spec/system/drawer/starred_channels_spec.rb
index 106d411da4b..51e1ac5951f 100644
--- a/plugins/chat/spec/system/drawer/starred_channels_spec.rb
+++ b/plugins/chat/spec/system/drawer/starred_channels_spec.rb
@@ -19,43 +19,14 @@ RSpec.describe "Drawer - starred channels", type: :system do
context "when user has starred channels" do
before { channel_1.membership_for(current_user).update!(starred: true) }
- it "defaults to starred channels when opening drawer" do
+ it "defaults to starred channels, shows footer tab, and can open channel" do
visit("/")
chat_page.open_from_header
- expect(drawer_page).to have_open_starred_channels
- end
-
- it "shows starred tab in footer" do
- visit("/")
- chat_page.open_from_header
-
- expect(page).to have_css("#c-footer-starred")
- end
-
- it "navigates to starred channels when clicking footer tab" do
- visit("/")
- chat_page.open_from_header
- drawer_page.click_starred_channels
-
expect(drawer_page).to have_open_starred_channels
expect(page).to have_css("#c-footer-starred.--active")
- end
-
- it "shows the starred channel in the list" do
- visit("/")
- chat_page.open_from_header
- drawer_page.click_starred_channels
-
- expect(page).to have_css(".chat-channel-row[data-chat-channel-id='#{channel_1.id}']")
- end
- it "can open a starred channel" do
- visit("/")
- chat_page.open_from_header
- drawer_page.click_starred_channels
find(".chat-channel-row[data-chat-channel-id='#{channel_1.id}']").click
-
expect(drawer_page).to have_open_channel(channel_1)
end
end
@@ -70,33 +41,19 @@ RSpec.describe "Drawer - starred channels", type: :system do
end
context "when user has starred both channels and DMs" do
- fab!(:user_1, :user)
- fab!(:user_2, :user)
+ fab!(:user_1) { Fabricate(:user, username: "alice") }
+ fab!(:user_2) { Fabricate(:user, username: "bob") }
fab!(:dm_channel_1) { Fabricate(:direct_message_channel, users: [current_user, user_1]) }
fab!(:dm_channel_2) { Fabricate(:direct_message_channel, users: [current_user, user_2]) }
before do
- user_1.update!(username: "alice")
- user_2.update!(username: "bob")
channel_1.membership_for(current_user).update!(starred: true)
channel_2.membership_for(current_user).update!(starred: true)
dm_channel_1.membership_for(current_user).update!(starred: true)
dm_channel_2.membership_for(current_user).update!(starred: true)
end
- it "shows regular channels before DMs in the starred channels list" do
- visit("/")
- chat_page.open_from_header
- drawer_page.click_starred_channels
-
- channels = page.all(".chat-channel-row")
- expect(channels[0]["data-chat-channel-id"]).to eq(channel_1.id.to_s)
- expect(channels[1]["data-chat-channel-id"]).to eq(channel_2.id.to_s)
- expect(channels[2]["data-chat-channel-id"]).to eq(dm_channel_1.id.to_s)
- expect(channels[3]["data-chat-channel-id"]).to eq(dm_channel_2.id.to_s)
- end
-
- it "shows regular channels with unreads before DMs with unreads" do
+ it "sorts by unreads first, then public channels before DMs" do
Fabricate(:chat_message, chat_channel: channel_2, user: user_1)
Fabricate(:chat_message, chat_channel: dm_channel_1, user: user_1)
channel_2.membership_for(current_user).update!(last_viewed_at: 1.minute.ago)
@@ -107,45 +64,36 @@ RSpec.describe "Drawer - starred channels", type: :system do
drawer_page.click_starred_channels
channels = page.all(".chat-channel-row")
- expect(channels[0]["data-chat-channel-id"]).to eq(channel_2.id.to_s)
- expect(channels[1]["data-chat-channel-id"]).to eq(channel_1.id.to_s)
- expect(channels[2]["data-chat-channel-id"]).to eq(dm_channel_1.id.to_s)
- expect(channels[3]["data-chat-channel-id"]).to eq(dm_channel_2.id.to_s)
+ expect(channels.map { |c| c["data-chat-channel-id"] }).to eq(
+ [channel_2.id, channel_1.id, dm_channel_1.id, dm_channel_2.id].map(&:to_s),
+ )
end
end
- context "when navigating from starred channels tab" do
- fab!(:user_1, :user)
- fab!(:dm_channel_1) { Fabricate(:direct_message_channel, users: [current_user, user_1]) }
-
- before do
- channel_1.membership_for(current_user).update!(starred: true)
- channel_2.membership_for(current_user).update!(starred: true)
- dm_channel_1.membership_for(current_user).update!(starred: true)
- end
+ context "when navigating back from a channel" do
+ before { channel_1.membership_for(current_user).update!(starred: true) }
- it "returns to starred channels tab when clicking back from a regular channel" do
+ it "returns to starred channels when starred channels exist" do
visit("/")
chat_page.open_from_header
drawer_page.click_starred_channels
-
find(".chat-channel-row[data-chat-channel-id='#{channel_1.id}']").click
- expect(drawer_page).to have_open_channel(channel_1)
find(".c-navbar__back-button").click
expect(drawer_page).to have_open_starred_channels
end
- it "returns to starred channels tab when clicking back from a DM" do
+ it "redirects to channels list after unstarring the last channel" do
visit("/")
chat_page.open_from_header
drawer_page.click_starred_channels
+ find(".chat-channel-row[data-chat-channel-id='#{channel_1.id}']").click
- find(".chat-channel-row[data-chat-channel-id='#{dm_channel_1.id}']").click
- expect(drawer_page).to have_open_channel(dm_channel_1)
+ find(".c-navbar__star-channel-button").click
+ expect(page).to have_no_css(".c-navbar__star-channel-button.--starred")
find(".c-navbar__back-button").click
- expect(drawer_page).to have_open_starred_channels
+ expect(drawer_page).to have_open_channels
end
end
end
diff --git a/plugins/chat/spec/system/starred_channels_spec.rb b/plugins/chat/spec/system/starred_channels_spec.rb
index 20bec52c35b..656996668f0 100644
--- a/plugins/chat/spec/system/starred_channels_spec.rb
+++ b/plugins/chat/spec/system/starred_channels_spec.rb
@@ -367,44 +367,35 @@ RSpec.describe "Starred channels", type: :system do
end
end
- context "when navigating from starred channels on mobile", mobile: true do
- fab!(:user_1, :user)
+ context "when navigating back from a channel on mobile", mobile: true do
fab!(:channel_1) { Fabricate(:category_channel, name: "Channel A") }
- fab!(:dm_channel_1) { Fabricate(:direct_message_channel, users: [current_user, user_1]) }
before do
channel_1.add(current_user)
channel_1.membership_for(current_user).update!(starred: true)
- dm_channel_1.membership_for(current_user).update!(starred: true)
end
- it "returns to starred channels when clicking back from a regular channel" do
+ it "returns to starred channels when starred channels exist" do
visit("/")
chat_page.open_from_header
-
- expect(page).to have_css("#c-footer-starred")
find("#c-footer-starred").click
- expect(page).to have_current_path("/chat/starred-channels")
-
find(".chat-channel-row[data-chat-channel-id='#{channel_1.id}']").click
- expect(page).to have_current_path(%r{/chat/c/.*/#{channel_1.id}})
find(".c-navbar__back-button").click
expect(page).to have_current_path("/chat/starred-channels")
end
- it "returns to starred channels when clicking back from a DM" do
+ it "redirects to channels list after unstarring the last channel" do
visit("/")
chat_page.open_from_header
-
find("#c-footer-starred").click
- expect(page).to have_current_path("/chat/starred-channels")
+ find(".chat-channel-row[data-chat-channel-id='#{channel_1.id}']").click
- find(".chat-channel-row[data-chat-channel-id='#{dm_channel_1.id}']").click
- expect(page).to have_current_path(%r{/chat/c/.*/#{dm_channel_1.id}})
+ find(".c-navbar__star-channel-button").click
+ expect(page).to have_no_css(".c-navbar__star-channel-button.--starred")
find(".c-navbar__back-button").click
- expect(page).to have_current_path("/chat/starred-channels")
+ expect(page).to have_current_path("/chat/channels")
end
end
end