diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/thread/header.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/thread/header.gjs index efb5525bf70..b7ab40cb00d 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat/thread/header.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat/thread/header.gjs @@ -40,6 +40,10 @@ export default class ChatThreadHeader extends Component { route = "chat.channel.threads"; title = I18n.t("chat.return_to_threads_list"); models = this.args.channel.routeModels; + } else if (!this.currentUser.isInDoNotDisturb() && this.unreadCount > 0) { + route = "chat.channel.threads"; + title = I18n.t("chat.return_to_threads_list"); + models = this.args.channel.routeModels; } else if (prevPage === "chat.threads") { route = "chat.threads"; title = I18n.t("chat.my_threads.title"); @@ -76,6 +80,10 @@ export default class ChatThreadHeader extends Component { return this.args.thread?.title ?? I18n.t("chat.thread.label"); } + get unreadCount() { + return this.args.channel.threadsManager.unreadThreadCount; + } + @action openThreadSettings() { this.modal.show(ChatModalThreadSettings, { model: this.args.thread }); diff --git a/plugins/chat/spec/system/navigation_spec.rb b/plugins/chat/spec/system/navigation_spec.rb index 19baa9be96d..5a1214e8f0d 100644 --- a/plugins/chat/spec/system/navigation_spec.rb +++ b/plugins/chat/spec/system/navigation_spec.rb @@ -161,6 +161,26 @@ RSpec.describe "Navigation", type: :system do expect(page).to have_current_path("#{category_channel.relative_url}/t") expect(thread_list_page).to have_loaded end + + context "when there are unread threads" do + fab!(:thread_2) { Fabricate(:chat_thread, channel: category_channel, use_service: true) } + + before { Fabricate(:chat_message, thread: thread_2, use_service: true) } + + it "goes back to the thread list when clicking the back button", mobile: true do + chat_page.visit_channel(category_channel) + channel_page.message_thread_indicator(thread.original_message).click + thread_page.send_message + thread_page.back + channel_page.message_thread_indicator(thread_2.original_message).click + Fabricate(:chat_message, thread: thread, use_service: true) + + expect(thread_page).to have_unread_list_indicator(count: 1) + expect(thread_page).to have_back_link_to_thread_list(category_channel) + thread_page.back + expect(page).to have_current_path("#{category_channel.relative_url}/t") + end + end end end