diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js b/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js index 6258e7a0ec2..9cd66d58ab5 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js @@ -20,7 +20,6 @@ import discourseLater from "discourse-common/lib/later"; import { inject as service } from "@ember/service"; import { Promise } from "rsvp"; import { resetIdle } from "discourse/lib/desktop-notifications"; -import { defaultHomepage } from "discourse/lib/utilities"; import { capitalize } from "@ember/string"; import { onPresenceChange, @@ -1269,12 +1268,14 @@ export default Component.extend({ this.chatPreferredMode.setDrawer(); this.appEvents.trigger("chat:open-channel", channel); - const previousRouteInfo = this.fullPageChat.exit(); - if (previousRouteInfo) { - this._transitionToRoute(previousRouteInfo); - } else { - this.router.transitionTo(`discovery.${defaultHomepage()}`); + let previousURL = this.fullPageChat.exit(); + if (!previousURL || previousURL === "/") { + previousURL = "discovery"; } + + this.router.replaceWith(previousURL).then(() => { + this.appEvents.trigger("chat:open-channel", channel); + }); }, @action @@ -1433,18 +1434,6 @@ export default Component.extend({ }); }, - _transitionToRoute(routeInfo) { - const routeName = routeInfo.name; - let params = []; - - do { - params = Object.values(routeInfo.params).concat(params); - routeInfo = routeInfo.parent; - } while (routeInfo); - - this.router.transitionTo(routeName, ...params); - }, - @bind _forceBodyScroll() { // when keyboard is visible this will ensure body diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat.js b/plugins/chat/assets/javascripts/discourse/routes/chat.js index cfda809d283..bacf20cb490 100644 --- a/plugins/chat/assets/javascripts/discourse/routes/chat.js +++ b/plugins/chat/assets/javascripts/discourse/routes/chat.js @@ -14,12 +14,12 @@ export default class ChatRoute extends DiscourseRoute { return I18n.t("chat.title_capitalized"); } - beforeModel(transition) { + beforeModel() { if (!this.chat.userCanChat) { return this.transitionTo(`discovery.${defaultHomepage()}`); } - this.fullPageChat.enter(transition?.from); + this.fullPageChat.enter(this.router.currentURL); } activate() { diff --git a/plugins/chat/assets/javascripts/discourse/services/full-page-chat.js b/plugins/chat/assets/javascripts/discourse/services/full-page-chat.js index 27587388725..56ad082c6a3 100644 --- a/plugins/chat/assets/javascripts/discourse/services/full-page-chat.js +++ b/plugins/chat/assets/javascripts/discourse/services/full-page-chat.js @@ -1,17 +1,17 @@ import Service from "@ember/service"; export default class FullPageChat extends Service { - _previousRouteInfo = null; + _previousURL = null; _isActive = false; - enter(previousRouteInfo) { - this._previousRouteInfo = previousRouteInfo; + enter(previousURL) { + this._previousURL = previousURL; this._isActive = true; } exit() { this._isActive = false; - return this._previousRouteInfo; + return this._previousURL; } get isActive() { diff --git a/plugins/chat/spec/system/navigation_spec.rb b/plugins/chat/spec/system/navigation_spec.rb index c964f873192..851a48c86bf 100644 --- a/plugins/chat/spec/system/navigation_spec.rb +++ b/plugins/chat/spec/system/navigation_spec.rb @@ -7,6 +7,7 @@ RSpec.describe "Navigation", type: :system, js: true do fab!(:user) { Fabricate(:admin) } fab!(:category_channel) { Fabricate(:category_channel) } fab!(:message) { Fabricate(:chat_message, chat_channel: category_channel) } + let(:chat_page) { PageObjects::Pages::Chat.new } before do # ensures we have one valid registered admin @@ -21,7 +22,7 @@ RSpec.describe "Navigation", type: :system, js: true do context "when visiting /chat" do it "opens full page" do - visit("/chat") + chat_page.open_full_page expect(page).to have_current_path( chat.channel_path(category_channel.id, category_channel.slug), @@ -34,7 +35,7 @@ RSpec.describe "Navigation", type: :system, js: true do context "when opening chat" do it "opens the drawer by default" do visit("/") - find(".open-chat").click + chat_page.open_from_header expect(page).to have_css(".topic-chat-container.expanded.visible") end @@ -43,15 +44,15 @@ RSpec.describe "Navigation", type: :system, js: true do context "when opening chat with full page as preferred mode" do it "opens the full page" do visit("/") - find(".open-chat").click - find(".topic-chat-drawer-header__full-screen-btn").click + chat_page.open_from_header + chat_page.maximize_drawer expect(page).to have_current_path( chat.channel_path(category_channel.id, category_channel.slug), ) visit("/") - find(".open-chat").click + chat_page.open_from_header expect(page).to have_current_path( chat.channel_path(category_channel.id, category_channel.slug), @@ -61,15 +62,36 @@ RSpec.describe "Navigation", type: :system, js: true do context "when opening chat with drawer as preferred mode" do it "opens the full page" do - visit("/chat") - find(".chat-full-screen-button").click + chat_page.open_full_page + chat_page.minimize_full_page expect(page).to have_css(".topic-chat-container.expanded.visible") visit("/") - find(".open-chat").click + chat_page.open_from_header expect(page).to have_css(".topic-chat-container.expanded.visible") end end + + context "when collapsing full page with no previous state" do + it "redirects to home page" do + chat_page.open_full_page + chat_page.minimize_full_page + + expect(page).to have_current_path("/") + end + end + + context "when collapsing full page with previous state" do + it "redirects to previous state" do + visit("/t/-/#{topic.id}") + chat_page.open_from_header + chat_page.maximize_drawer + chat_page.minimize_full_page + + expect(page).to have_current_path("/t/#{topic.slug}/#{topic.id}") + expect(page).to have_css(".chat-message-container[data-id='#{message.id}']") + end + end end diff --git a/plugins/chat/spec/system/page_objects/chat/chat.rb b/plugins/chat/spec/system/page_objects/chat/chat.rb new file mode 100644 index 00000000000..a2e9e840ae2 --- /dev/null +++ b/plugins/chat/spec/system/page_objects/chat/chat.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module PageObjects + module Pages + class Chat < PageObjects::Pages::Base + def open_from_header + find(".open-chat").click + end + + def open_full_page + visit("/chat") + end + + def maximize_drawer + find(".topic-chat-drawer-header__full-screen-btn").click + end + + def minimize_full_page + find(".chat-full-screen-button").click + end + end + end +end