A platform for community discussion. Free, open, simple.
REFACTOR: handles every chat resource as an URL (#18961)
Joffrey JAFFEUX66130dc8c12b
diff --git a/plugins/chat/assets/javascripts/discourse/components/channels-list.js b/plugins/chat/assets/javascripts/discourse/components/channels-list.jsindex bd1a8592b8b..ae145525a02 100644--- a/plugins/chat/assets/javascripts/discourse/components/channels-list.js+++ b/plugins/chat/assets/javascripts/discourse/components/channels-list.js@@ -4,15 +4,14 @@ import { action, computed } from "@ember/object";import { schedule } from "@ember/runloop";import { inject as service } from "@ember/service";import { and, empty, reads } from "@ember/object/computed";-import { DRAFT_CHANNEL_VIEW } from "discourse/plugins/chat/discourse/services/chat";export default class ChannelsList extends Component {@service chat;@service router;+ @service chatStateManager;tagName = "";inSidebar = false;toggleSection = null;- onSelect = null;@reads("chat.publicChannels.[]") publicChannels;@reads("chat.directMessageChannels.[]") directMessageChannels;@empty("publicChannels") publicChannelsEmpty;@@ -80,24 +79,6 @@ export default class ChannelsList extends Component {}`;}- @action- browseChannels() {- this.router.transitionTo("chat.browse");- return false;- }-- @action- startCreatingDmChannel() {- if (- this.site.mobileView ||- this.router.currentRouteName.startsWith("chat.")- ) {- this.router.transitionTo("chat.draft-channel");- } else {- this.appEvents.trigger("chat:open-view", DRAFT_CHANNEL_VIEW);- }- }-@actiontoggleChannelSection(section) {this.toggleSection(section);diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-browse-view.js b/plugins/chat/assets/javascripts/discourse/components/chat-browse-view.jsindex b270b19cd0b..a453ad360fe 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-browse-view.js+++ b/plugins/chat/assets/javascripts/discourse/components/chat-browse-view.js@@ -87,11 +87,6 @@ export default class ChatBrowseView extends Component {showModal("create-channel");}- @action- returnToChannelsList() {- return this.router.transitionTo("chat.index");- }-@bindfilterChannels(filter) {this.canLoadMore = true;diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-row.js b/plugins/chat/assets/javascripts/discourse/components/chat-channel-row.jsindex bc8b6ad4216..ae3b281645c 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-row.js+++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel-row.js@@ -1,8 +1,6 @@import Component from "@ember/component";import I18n from "I18n";import discourseComputed from "discourse-common/utils/decorators";-import getURL from "discourse-common/lib/get-url";-import { action } from "@ember/object";import { equal } from "@ember/object/computed";import { inject as service } from "@ember/service";import { CHATABLE_TYPES } from "discourse/plugins/chat/discourse/models/chat-channel";@@ -12,7 +10,6 @@ export default Component.extend({router: service(),chat: service(),channel: null,- switchChannel: null,isDirectMessageRow: equal("channel.chatable_type",CHATABLE_TYPES.directMessageChannel@@ -75,52 +72,6 @@ export default Component.extend({);},- @action- handleNewWindow(event) {- // Middle mouse click- if (event.which === 2) {- window- .open(- getURL(`/chat/channel/${this.channel.id}/${this.channel.title}`),- "_blank"- )- .focus();- }- },-- @action- handleSwitchChannel(event) {- if (this.switchChannel) {- this.switchChannel(this.channel);- event.preventDefault();- }- },-- @action- handleClick(event) {- if (event.target.classList.contains("chat-channel-leave-btn")) {- return true;- }-- if (- event.target.classList.contains("chat-channel-settings-btn") ||- event.target.parentElement.classList.contains("select-kit-header-wrapper")- ) {- return;- }-- this.handleSwitchChannel(event);- },-- @action- handleKeyUp(event) {- if (event.key !== "Enter") {- return;- }-- this.handleSwitchChannel(event);- },-@discourseComputed("channel.chatable_type")leaveChatTitle() {if (this.channel.isDirectMessageChannel) {diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-composer-uploads.js b/plugins/chat/assets/javascripts/discourse/components/chat-composer-uploads.jsindex f4b6877bf5c..dba574f9631 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-composer-uploads.js+++ b/plugins/chat/assets/javascripts/discourse/components/chat-composer-uploads.js@@ -9,11 +9,11 @@ import UppyUploadMixin from "discourse/mixins/uppy-upload";export default Component.extend(UppyUploadMixin, {classNames: ["chat-composer-uploads"],mediaOptimizationWorker: service(),+ chatStateManager: service(),id: "chat-composer-uploader",type: "chat-composer",uploads: null,useMultipartUploadsIfAvailable: true,- fullPage: false,init() {this._super(...arguments);@@ -66,7 +66,7 @@ export default Component.extend(UppyUploadMixin, {_uploadDropTargetOptions() {let targetEl;- if (this.fullPage) {+ if (this.chatStateManager.isFullPage) {targetEl = document.querySelector(".full-page-chat");} else {targetEl = document.querySelector(diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-composer.js b/plugins/chat/assets/javascripts/discourse/components/chat-composer.jsindex ad4f55e8d1e..bb9f68be19c 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-composer.js+++ b/plugins/chat/assets/javascripts/discourse/components/chat-composer.js@@ -37,8 +37,8 @@ export default Component.extend(TextareaTextManipulation, {userSilenced: readOnly("details.user_silenced"),chatEmojiReactionStore: service("chat-emoji-reaction-store"),chatEmojiPickerManager: service("chat-emoji-picker-manager"),+ chatStateManager: service("chat-state-manager"),editingMessage: null,- fullPage: false,onValueChange: null,timer: null,value: "",@@ -63,7 +63,7 @@ export default Component.extend(TextareaTextManipulation, {return picker.opened && picker.context === "chat-composer";},- @discourseComputed("fullPage")+ @discourseComputed("chatStateManager.isFullPage")fileUploadElementId(fullPage) {return fullPage ? "chat-full-page-uploader" : "chat-widget-uploader";},diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js b/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.jsindex 85ca678d633..c23974fa4ed 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js+++ b/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js@@ -41,7 +41,6 @@ const FUTURE = "future";export default Component.extend({classNameBindings: [":chat-live-pane", "sendingLoading", "loading"],chatChannel: null,- fullPage: false,registeredChatChannelId: null, // ?Numberloading: false,loadingMorePast: false,@@ -73,8 +72,7 @@ export default Component.extend({router: service(),chatEmojiPickerManager: service(),chatComposerPresenceManager: service(),- chatPreferredMode: service(),- fullPageChat: service(),+ chatStateManager: service(),getCachedChannelDetails: null,clearCachedChannelDetails: null,@@ -1264,11 +1262,14 @@ export default Component.extend({},@action- onCloseFullScreen(channel) {- this.chatPreferredMode.setDrawer();+ onCloseFullScreen() {+ this.chatStateManager.prefersDrawer();- this.router.replaceWith(this.fullPageChat.exit()).then(() => {- this.appEvents.trigger("chat:open-channel", channel);+ this.router.transitionTo(this.chatStateManager.lastKnownAppURL).then(() => {+ this.appEvents.trigger(+ "chat:open-url",+ this.chatStateManager.lastKnownChatURL+ );});},diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-message-actions-desktop.js b/plugins/chat/assets/javascripts/discourse/components/chat-message-actions-desktop.jsindex 2affd3718dc..5a7e3e1434d 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-message-actions-desktop.js+++ b/plugins/chat/assets/javascripts/discourse/components/chat-message-actions-desktop.js@@ -10,7 +10,7 @@ const MSG_ACTIONS_VERTICAL_PADDING = -15;export default Component.extend({tagName: "",- chatPreferredMode: service(),+ chatStateManager: service(),messageActions: null,diff --git a/plugins/chat/assets/javascripts/discourse/components/direct-message-creator.js b/plugins/chat/assets/javascripts/discourse/components/direct-message-creator.jsindex 426029db34e..66cd36bcee9 100644--- a/plugins/chat/assets/javascripts/discourse/components/direct-message-creator.js+++ b/plugins/chat/assets/javascripts/discourse/components/direct-message-creator.js@@ -21,6 +21,7 @@ export default Component.extend({focusedUser: null,chat: service(),router: service(),+ chatStateManager: service(),isLoading: false,onSwitchChannel: null,diff --git a/plugins/chat/assets/javascripts/discourse/components/topic-chat-float.js b/plugins/chat/assets/javascripts/discourse/components/topic-chat-float.jsindex 740823856f7..414df2c98b9 100644--- a/plugins/chat/assets/javascripts/discourse/components/topic-chat-float.js+++ b/plugins/chat/assets/javascripts/discourse/components/topic-chat-float.js@@ -1,6 +1,5 @@import Component from "@ember/component";import discourseComputed, { observes } from "discourse-common/utils/decorators";-import getURL from "discourse-common/lib/get-url";import { action } from "@ember/object";import {CHAT_VIEW,@@ -18,7 +17,7 @@ export default Component.extend({classNameBindings: [":topic-chat-float-container", "hidden"],chat: service(),router: service(),- chatPreferredMode: service(),+ chatStateManager: service(),hidden: true,loading: false,expanded: true, // TODO - false when not first-load topic@@ -35,15 +34,8 @@ export default Component.extend({}this._checkSize();- this.appEvents.on("chat:navigated-to-full-page", this, "close");- this.appEvents.on("chat:open-view", this, "openView");- this.appEvents.on("chat:toggle-open", this, "toggleChat");+ this.appEvents.on("chat:open-url", this, "openURL");this.appEvents.on("chat:toggle-close", this, "close");- this.appEvents.on(- "chat:open-channel-for-chatable",- this,- "openChannelForChatable"- );this.appEvents.on("chat:open-channel", this, "switchChannel");this.appEvents.on("chat:open-channel-at-message",@@ -70,15 +62,8 @@ export default Component.extend({}if (this.appEvents) {- this.appEvents.off("chat:open-view", this, "openView");- this.appEvents.off("chat:navigated-to-full-page", this, "close");- this.appEvents.off("chat:toggle-open", this, "toggleChat");+ this.appEvents.off("chat:open-url", this, "openURL");this.appEvents.off("chat:toggle-close", this, "close");- this.appEvents.off(- "chat:open-channel-for-chatable",- this,- "openChannelForChatable"- );this.appEvents.off("chat:open-channel", this, "switchChannel");this.appEvents.off("chat:open-channel-at-message",@@ -116,14 +101,6 @@ export default Component.extend({this.appEvents.trigger("chat:rerender-header");},- async openChannelForChatable(channel) {- if (!channel) {- return;- }-- this.switchChannel(channel);- },-@discourseComputed("expanded")topLineClass(expanded) {const baseClass = "topic-chat-drawer-header__top-line";@@ -225,38 +202,45 @@ export default Component.extend({},@action- openView(view) {- this.setProperties({- hidden: false,- expanded: true,- view,- });+ openURL(URL = null) {+ this.set("hidden", false);+ this.set("expanded", true);- this.appEvents.trigger("chat:float-toggled", false);- },-- @action- openInFullPage(e) {- this.chatPreferredMode.setFullPage();+ this.chatStateManager.storeChatURL(URL);- const channel = this.chat.activeChannel;- this.set("expanded", false);- this.set("hidden", true);- this.chat.setActiveChannel(null);+ const route = this._buildRouteFromURL(+ URL || this.chatStateManager.lastKnownChatURL+ );- if (!channel) {- return this.router.transitionTo("chat");+ switch (route.name) {+ case "chat":+ this.chat.setActiveChannel(null);+ this.set("view", LIST_VIEW);+ this.appEvents.trigger("chat:float-toggled", false);+ return;+ case "chat.draft-channel":+ this.chat.setActiveChannel(null);+ this.set("view", DRAFT_CHANNEL_VIEW);+ this.appEvents.trigger("chat:float-toggled", false);+ return;+ case "chat.channel":+ return this.chat+ .getChannelBy("id", route.params.channelId)+ .then((channel) => {+ this.chat.setActiveChannel(channel);+ this.set("view", CHAT_VIEW);+ this.appEvents.trigger("chat:float-toggled", false);+ });}+ },- if (e.which === 2) {- // Middle mouse click- window- .open(getURL(`/chat/channel/${channel.id}/${channel.title}`), "_blank")- .focus();- return false;- }+ @action+ openInFullPage() {+ this.chatStateManager.storeAppURL();+ this.chatStateManager.prefersFullPage();+ this.chat.setActiveChannel(null);- this.chat.openChannel(channel);+ return this.router.transitionTo(this.chatStateManager.lastKnownChatURL);},@action@@ -267,42 +251,11 @@ export default Component.extend({@actionclose() {- this.setProperties({- hidden: true,- expanded: false,- });- this.chat.setActiveChannel(null);+ this.set("hidden", true);+ this.set("expanded", false);this.appEvents.trigger("chat:float-toggled", this.hidden);},- @action- toggleChat() {- this.set("hidden", !this.hidden);- this.appEvents.trigger("chat:float-toggled", this.hidden);- if (this.hidden) {- return this.chat.setActiveChannel(null);- } else {- this.set("expanded", true);- this.appEvents.trigger("chat:toggle-expand", this.expanded);- if (this.chat.activeChannel) {- // Channel was previously open, so after expand we are done.- return this.chat.setActiveChannel(null);- }- }-- // Look for DM channel with unread, and fallback to public channel with unread- this.chat.getIdealFirstChannelId().then((channelId) => {- if (channelId) {- this.chat.getChannelBy("id", channelId).then((channel) => {- this.switchChannel(channel);- });- } else {- // No channels with unread messages. Fetch channel index.- this.fetchChannels();- }- });- },-@actionrefreshChannels() {if (this.view === LIST_VIEW) {@@ -341,11 +294,41 @@ export default Component.extend({this.chat.setActiveChannel(channel);if (!channel) {- this.openView(LIST_VIEW);+ const URL = this._buildURLFromState(LIST_VIEW);+ this.openURL(URL);return;}- this.openView(CHAT_VIEW);+ const URL = this._buildURLFromState(CHAT_VIEW, channel);+ this.openURL(URL);});},++ _buildRouteFromURL(URL) {+ let route = this.router.recognize(URL || "/");++ // ember might recognize the index subroute+ if (route.localName === "index") {+ route = route.parent;+ }++ return route;+ },++ _buildURLFromState(view, channel = null) {+ switch (view) {+ case LIST_VIEW:+ return "/chat";+ case DRAFT_CHANNEL_VIEW:+ return "/chat/draft-channel";+ case CHAT_VIEW:+ if (channel) {+ return `/chat/channel/${channel.id}/${channel.slug || "-"}`;+ } else {+ return "/chat";+ }+ default:+ return "/chat";+ }+ },});diff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-keyboard-shortcuts.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-keyboard-shortcuts.jsindex d80c9948892..6b993a70d47 100644--- a/plugins/chat/assets/javascripts/discourse/initializers/chat-keyboard-shortcuts.js+++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-keyboard-shortcuts.js@@ -14,7 +14,9 @@ export default {return;}+ const router = container.lookup("service:router");const appEvents = container.lookup("service:app-events");+ const chatStateManager = container.lookup("service:chat-state-manager");const openChannelSelector = (e) => {e.preventDefault();e.stopPropagation();@@ -77,7 +79,9 @@ export default {}event.preventDefault();event.stopPropagation();- appEvents.trigger("chat:toggle-open", event);++ chatStateManager.prefersDrawer();+ router.transitionTo(chatStateManager.lastKnownChatURL || "chat");};const closeChatDrawer = (event) => {diff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.jsindex a190e99a4b9..32a002eeb0e 100644--- a/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js+++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js@@ -4,7 +4,6 @@ import { withPluginApi } from "discourse/lib/plugin-api";import I18n from "I18n";import { bind } from "discourse-common/utils/decorators";import { tracked } from "@glimmer/tracking";-import { DRAFT_CHANNEL_VIEW } from "discourse/plugins/chat/discourse/services/chat";import { avatarUrl, escapeExpression } from "discourse/lib/utilities";import { dasherize } from "@ember/string";import { emojiUnescape } from "discourse/lib/text";@@ -136,19 +135,18 @@ export default {return;}this.chatService = container.lookup("service:chat");- this.chatService.appEvents.on(- "chat:refresh-channels",- this._refreshChannels- );+ this.router = container.lookup("service:router");+ this.appEvents = container.lookup("service:app-events");+ this.appEvents.on("chat:refresh-channels", this._refreshChannels);this._refreshChannels();}@bindwillDestroy() {- if (!this.chatService) {+ if (!this.appEvents) {return;}- this.chatService.appEvents.off(+ this.appEvents.off("chat:refresh-channels",this._refreshChannels);@@ -187,9 +185,7 @@ export default {{id: "browseChannels",title: I18n.t("chat.channels_list_popup.browse"),- action: () => {- this.chatService.router.transitionTo("chat.browse");- },+ action: () => this.router.transitionTo("chat.browse.open"),},];}@@ -336,7 +332,9 @@ export default {}get hoverAction() {- return () => {+ return (event) => {+ event.stopPropagation();+ event.preventDefault();this.chatService.unfollowChannel(this.channel);};}@@ -371,6 +369,7 @@ export default {const SidebarChatDirectMessagesSection = class extends BaseCustomSidebarSection {@service site;+ @service router;@tracked sectionLinks = [];@tracked userCanDirectMessage =this.chatService.userCanDirectMessage;@@ -440,19 +439,7 @@ export default {id: "startDm",title: I18n.t("chat.direct_messages.new"),action: () => {- if (- this.site.mobileView ||- this.chatService.router.currentRouteName.startsWith("")- ) {- this.chatService.router.transitionTo(- "chat.draft-channel"- );- } else {- this.appEvents.trigger(- "chat:open-view",- DRAFT_CHANNEL_VIEW- );- }+ this.router.transitionTo("chat.draft-channel");},},];diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat-channel.js b/plugins/chat/assets/javascripts/discourse/routes/chat-channel.jsindex 999870ac8a5..17e6a2f7456 100644--- a/plugins/chat/assets/javascripts/discourse/routes/chat-channel.js+++ b/plugins/chat/assets/javascripts/discourse/routes/chat-channel.js@@ -8,8 +8,7 @@ import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channelexport default class ChatChannelRoute extends DiscourseRoute {@service chat;- @service fullPageChat;- @service chatPreferredMode;+ @service router;async model(params) {let [chatChannel, channels] = await Promise.all([@@ -38,13 +37,12 @@ export default class ChatChannelRoute extends DiscourseRoute {}afterModel(model) {- this.appEvents.trigger("chat:navigated-to-full-page");this.chat.setActiveChannel(model?.chatChannel);const queryParams = this.paramsFor(this.routeName);const slug = slugifyChannel(model.chatChannel);if (queryParams?.channelTitle !== slug) {- this.replaceWith("chat.channel.index", model.chatChannel.id, slug);+ this.router.replaceWith("chat.channel.index", model.chatChannel.id, slug);}}diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat.js b/plugins/chat/assets/javascripts/discourse/routes/chat.jsindex 863d5d7fc1a..04310b7a2c1 100644--- a/plugins/chat/assets/javascripts/discourse/routes/chat.js+++ b/plugins/chat/assets/javascripts/discourse/routes/chat.js@@ -4,46 +4,59 @@ import { defaultHomepage } from "discourse/lib/utilities";import { inject as service } from "@ember/service";import { scrollTop } from "discourse/mixins/scroll-top";import { schedule } from "@ember/runloop";-import { DRAFT_CHANNEL_VIEW } from "discourse/plugins/chat/discourse/services/chat";+import { action } from "@ember/object";export default class ChatRoute extends DiscourseRoute {@service chat;@service router;- @service fullPageChat;- @service chatPreferredMode;+ @service chatStateManager;titleToken() {return I18n.t("chat.title_capitalized");}beforeModel(transition) {+ if (!this.chat.userCanChat) {+ return this.router.transitionTo(`discovery.${defaultHomepage()}`);+ }++ const INTERCEPTABLE_ROUTES = [+ "chat.channel.index",+ "chat.channel",+ "chat",+ "chat.index",+ "chat.draft-channel",+ ];+if (transition.from && // don't intercept when directly loading chat- this.chatPreferredMode.isDrawer+ this.chatStateManager.isDrawerPreferred &&+ INTERCEPTABLE_ROUTES.includes(transition.targetName)) {- if (transition.intent?.name === "chat.channel") {- transition.abort();- const id = transition.intent.contexts[0];- return this.chat.getChannelBy("id", id).then((channel) => {- this.appEvents.trigger("chat:open-channel", channel);- });- }+ transition.abort();- if (transition.intent?.name === "chat.draft-channel") {- transition.abort();- this.appEvents.trigger("chat:open-view", DRAFT_CHANNEL_VIEW);- return;+ let URL = transition.intent.url;+ if (+ transition.targetName === "chat.channel.index" ||+ transition.targetName === "chat.channel"+ ) {+ URL ??= this.router.urlFor(+ transition.targetName,+ ...transition.intent.contexts+ );+ } else {+ URL ??= this.router.urlFor(transition.targetName);}- }- if (!this.chat.userCanChat) {- return this.router.transitionTo(`discovery.${defaultHomepage()}`);+ this.appEvents.trigger("chat:open-url", URL);+ return;}- this.fullPageChat.enter(this.router.currentURL);+ this.appEvents.trigger("chat:toggle-close");}activate() {+ this.chatStateManager.storeAppURL();this.chat.updatePresence();schedule("afterRender", () => {@@ -53,7 +66,6 @@ export default class ChatRoute extends DiscourseRoute {}deactivate() {- this.fullPageChat.exit();this.chat.setActiveChannel(null);schedule("afterRender", () => {@@ -62,4 +74,11 @@ export default class ChatRoute extends DiscourseRoute {scrollTop();});}++ @action+ willTransition(transition) {+ if (!transition?.to?.name?.startsWith("chat.")) {+ this.chatStateManager.storeChatURL();+ }+ }}diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-preferred-mode.js b/plugins/chat/assets/javascripts/discourse/services/chat-preferred-mode.jsdeleted file mode 100644index fa49c428ec1..00000000000--- a/plugins/chat/assets/javascripts/discourse/services/chat-preferred-mode.js+++ /dev/null@@ -1,35 +0,0 @@-import KeyValueStore from "discourse/lib/key-value-store";-import Service from "@ember/service";-import Site from "discourse/models/site";--const PREFERRED_MODE_KEY = "preferred_mode";-const PREFERRED_MODE_STORE_NAMESPACE = "discourse_chat_";-const FULL_PAGE_CHAT = "FULL_PAGE_CHAT";-const DRAWER_CHAT = "DRAWER_CHAT";--export default class ChatPreferredMode extends Service {- _store = new KeyValueStore(PREFERRED_MODE_STORE_NAMESPACE);-- setFullPage() {- this._store.setObject({ key: PREFERRED_MODE_KEY, value: FULL_PAGE_CHAT });- }-- setDrawer() {- this._store.setObject({ key: PREFERRED_MODE_KEY, value: DRAWER_CHAT });- }-- get isFullPage() {- return !!(- Site.currentProp("mobileView") ||- this._store.getObject(PREFERRED_MODE_KEY) === FULL_PAGE_CHAT- );- }-- get isDrawer() {- return !!(- !Site.currentProp("mobileView") &&- (!this._store.getObject(PREFERRED_MODE_KEY) ||- this._store.getObject(PREFERRED_MODE_KEY) === DRAWER_CHAT)- );- }-}diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-state-manager.js b/plugins/chat/assets/javascripts/discourse/services/chat-state-manager.jsnew file mode 100644index 00000000000..38fe1af7e59--- /dev/null+++ b/plugins/chat/assets/javascripts/discourse/services/chat-state-manager.js@@ -0,0 +1,73 @@+import Service, { inject as service } from "@ember/service";+import { defaultHomepage } from "discourse/lib/utilities";+import { tracked } from "@glimmer/tracking";+import KeyValueStore from "discourse/lib/key-value-store";+import Site from "discourse/models/site";++const PREFERRED_MODE_KEY = "preferred_mode";+const PREFERRED_MODE_STORE_NAMESPACE = "discourse_chat_";+const FULL_PAGE_CHAT = "FULL_PAGE_CHAT";+const DRAWER_CHAT = "DRAWER_CHAT";++export default class ChatStateManager extends Service {+ @service router;+ @tracked _chatURL = null;+ @tracked _appURL = null;++ _store = new KeyValueStore(PREFERRED_MODE_STORE_NAMESPACE);++ reset() {+ this._store.remove(PREFERRED_MODE_KEY);+ this._chatURL = null;+ this._appURL = null;+ }++ prefersFullPage() {+ this._store.setObject({ key: PREFERRED_MODE_KEY, value: FULL_PAGE_CHAT });+ }++ prefersDrawer() {+ this._store.setObject({ key: PREFERRED_MODE_KEY, value: DRAWER_CHAT });+ }++ get isFullPagePreferred() {+ return !!(+ Site.currentProp("mobileView") ||+ this._store.getObject(PREFERRED_MODE_KEY) === FULL_PAGE_CHAT+ );+ }++ get isDrawerPreferred() {+ return !!(+ !this.isFullPagePreferred ||+ (!Site.currentProp("mobileView") &&+ (!this._store.getObject(PREFERRED_MODE_KEY) ||+ this._store.getObject(PREFERRED_MODE_KEY) === DRAWER_CHAT))+ );+ }++ get isFullPage() {+ return this.router.currentRouteName?.startsWith("chat");+ }++ storeAppURL(URL = null) {+ this._appURL = URL || this.router.currentURL;+ }++ storeChatURL(URL = null) {+ this._chatURL = URL || this.router.currentURL;+ }++ get lastKnownAppURL() {+ let url = this._appURL;+ if (!url || url === "/") {+ url = this.router.urlFor(`discovery.${defaultHomepage()}`);+ }++ return url;+ }++ get lastKnownChatURL() {+ return this._chatURL || "/chat";+ }+}diff --git a/plugins/chat/assets/javascripts/discourse/services/chat.js b/plugins/chat/assets/javascripts/discourse/services/chat.jsindex 237e8328cf4..bf8a59b839c 100644--- a/plugins/chat/assets/javascripts/discourse/services/chat.js+++ b/plugins/chat/assets/javascripts/discourse/services/chat.js@@ -35,8 +35,7 @@ const READ_INTERVAL = 1000;export default class Chat extends Service {@service appEvents;@service chatNotificationManager;- @service chatPreferredMode;- @service fullPageChat;+ @service chatStateManager;@service presence;@service router;@service site;@@ -177,7 +176,7 @@ export default class Chat extends Service {updatePresence() {next(() => {- if (this.fullPageChat.isActive || this.chatOpen) {+ if (this.chatStateManager.isFullPage || this.chatOpen) {this.presenceChannel.enter({ activeOptions: CHAT_ONLINE_OPTIONS });} else {this.presenceChannel.leave();@@ -526,9 +525,9 @@ export default class Chat extends Service {this.setActiveChannel(channel);if (- this.fullPageChat.isActive ||+ this.chatStateManager.isFullPage ||this.site.mobileView ||- this.chatPreferredMode.isFullPage+ this.chatStateManager.isFullPagePreferred) {const queryParams = messageId ? { messageId } : {};@@ -748,7 +747,7 @@ export default class Chat extends Service {this._unsubscribeFromChatChannel(channel);this.stopTrackingChannel(channel);- if (channel.isDirectMessageChannel) {+ if (channel === this.activeChannel && channel.isDirectMessageChannel) {this.router.transitionTo("chat");}});diff --git a/plugins/chat/assets/javascripts/discourse/services/full-page-chat.js b/plugins/chat/assets/javascripts/discourse/services/full-page-chat.jsdeleted file mode 100644index 9b7d2cd6f92..00000000000--- a/plugins/chat/assets/javascripts/discourse/services/full-page-chat.js+++ /dev/null@@ -1,35 +0,0 @@-import Service, { inject as service } from "@ember/service";-import { defaultHomepage } from "discourse/lib/utilities";--export default class FullPageChat extends Service {- @service router;-- _previousURL = null;- _isActive = false;-- enter(previousURL) {- this._previousURL = previousURL;- this._isActive = true;- }-- exit() {- if (this.isDestroyed || this.isDestroying) {- return;- }-- this._isActive = false;-- let previousURL = this._previousURL;- if (!previousURL || previousURL === "/") {- previousURL = this.router.urlFor(`discovery.${defaultHomepage()}`);- }-- this._previousURL = null;-- return previousURL;- }-- get isActive() {- return this._isActive;- }-}diff --git a/plugins/chat/assets/javascripts/discourse/templates/chat-channel-index.hbs b/plugins/chat/assets/javascripts/discourse/templates/chat-channel-index.hbsindex 3aaeca4ccc0..dc261f00413 100644--- a/plugins/chat/assets/javascripts/discourse/templates/chat-channel-index.hbs+++ b/plugins/chat/assets/javascripts/discourse/templates/chat-channel-index.hbs@@ -1 +1 @@-<FullPageChat @chatChannel={{this.model.chatChannel}} @refreshModel={{route-action "refreshModel"}} />+<FullPageChat @refreshModel={{route-action "refreshModel"}} />diff --git a/plugins/chat/assets/javascripts/discourse/templates/chat-channel-info.hbs b/plugins/chat/assets/javascripts/discourse/templates/chat-channel-info.hbsindex fc488396a5f..e7e0ba3aacb 100644--- a/plugins/chat/assets/javascripts/discourse/templates/chat-channel-info.hbs+++ b/plugins/chat/assets/javascripts/discourse/templates/chat-channel-info.hbs@@ -1,29 +1,26 @@<div class="channel-info"><div class="chat-full-page-header">- {{#if this.chatChannelInfoRouteOriginManager.isBrowse}}- <LinkTo @route="chat.browse" class="channel-info__back-btn">- {{d-icon "chevron-left"}}- <span>- {{i18n "chat.channel_info.back_to_all_channels"}}- </span>- </LinkTo>- {{else}}- <LinkTo- @route="chat.channel"- @models={{array- this.model.chatChannel.id- (slugify-channel this.model.chatChannel)- }}- class="channel-info__back-btn"- >- {{d-icon "chevron-left"}}- <span>- {{i18n "chat.channel_info.back_to_channel"}}- </span>- </LinkTo>- {{/if}}-<div class="chat-channel-header-details">+ <div class="chat-full-page-header__left-actions">+ {{#if this.chatChannelInfoRouteOriginManager.isBrowse}}+ <LinkTo @route="chat.browse" class="chat-full-page-header__back-btn no-text btn-flat btn" title={{i18n "chat.channel_info.back_to_all_channel"}}>+ {{d-icon "chevron-left"}}+ </LinkTo>+ {{else}}+ <LinkTo+ @route="chat.channel"+ @models={{array+ this.model.chatChannel.id+ (slugify-channel this.model.chatChannel)+ }}+ class="chat-full-page-header__back-btn no-text btn-flat btn"+ title={{i18n "chat.channel_info.back_to_channel"}}+ >+ {{d-icon "chevron-left"}}+ </LinkTo>+ {{/if}}+ </div>+<ChatChannelTitle @channel={{this.model.chatChannel}} /></div></div>diff --git a/plugins/chat/assets/javascripts/discourse/templates/components/channels-list.hbs b/plugins/chat/assets/javascripts/discourse/templates/components/channels-list.hbsindex a168185d2e3..f63caef0ecf 100644--- a/plugins/chat/assets/javascripts/discourse/templates/components/channels-list.hbs+++ b/plugins/chat/assets/javascripts/discourse/templates/components/channels-list.hbs@@ -1,11 +1,7 @@-{{#if this.showMobileDirectMessageButton}}- <DButton- @class="btn-flat new-dm keep-mobile-sidebar-open btn-floating"- @icon="plus"- @action={{action "startCreatingDmChannel"}}- @title={{this.createDirectMessageChannelLabel}}- @disabled={{not this.canCreateDirectMessageChannel}}- />+{{#if (and this.showMobileDirectMessageButton this.canCreateDirectMessageChannel)}}+ <LinkTo @route="chat.draft-channel" class="btn-flat open-draft-channel-page-btn keep-mobile-sidebar-open btn-floating" title={{i18n this.createDirectMessageChannelLabel}}>+ {{d-icon "plus"}}+ </LinkTo>{{/if}}<div@@ -30,11 +26,9 @@{{/if}}<span class="channel-title">{{i18n "chat.chat_channels"}}</span>- <DButton- @action={{action "browseChannels"}}- @icon="pencil-alt"- @class="btn-flat edit-channel-membership-btn title-action"- />+ <LinkTo @route="chat.browse" class="btn no-text btn-flat open-browse-page-btn title-action" title={{i18n "chat.channels_list_popup.browse"}}>+ {{d-icon "pencil-alt"}}+ </LinkTo></div><div id="public-channels" class={{this.publicChannelClasses}}>@@ -49,7 +43,6 @@{{#each this.publicChannels as |channel|}}<ChatChannelRow@channel={{channel}}- @switchChannel={{this.onSelect}}@options={{hash settingsButton=true}}/>{{/each}}@@ -82,14 +75,10 @@{{/if}}<span class="channel-title">{{i18n "chat.direct_messages.title"}}</span>- {{#if this.site.desktopView}}- <DButton- @class="btn-flat new-dm keep-mobile-sidebar-open"- @icon="plus"- @action={{action "startCreatingDmChannel"}}- @title={{this.createDirectMessageChannelLabel}}- @disabled={{not this.canCreateDirectMessageChannel}}- />+ {{#if (and this.canCreateDirectMessageChannel (not this.showMobileDirectMessageButton))}}+ <LinkTo @route="chat.draft-channel" class="btn no-text btn-flat open-draft-channel-page-btn" title={{i18n this.createDirectMessageChannelLabel}}>+ {{d-icon "plus"}}+ </LinkTo>{{/if}}</div>{{/if}}@@ -98,7 +87,6 @@{{#each this.sortedDirectMessageChannels as |channel|}}<ChatChannelRow@channel={{channel}}- @switchChannel={{this.onSelect}}@options={{hash leaveButton=true}}/>{{/each}}diff --git a/plugins/chat/assets/javascripts/discourse/templates/components/chat-browse-view.hbs b/plugins/chat/assets/javascripts/discourse/templates/components/chat-browse-view.hbsindex e184b88167d..b8e659f9923 100644--- a/plugins/chat/assets/javascripts/discourse/templates/components/chat-browse-view.hbs+++ b/plugins/chat/assets/javascripts/discourse/templates/components/chat-browse-view.hbs@@ -4,27 +4,26 @@{{/in-element}}{{/if}}-<div class="chat-browse-view">- <div class="chat-browse-view__header">- {{#if this.site.mobileView}}- <DButton- @action={{action "returnToChannelsList"}}- @icon="chevron-left"- @class="chat-browse-view__back"- @title="chat.browse.back"- />- {{/if}}- <h1 class="chat-browse-view__title">{{i18n "chat.browse.title"}}</h1>- {{#if this.currentUser.staff}}- <DButton- @action={{action "createChannel"}}- @icon="plus"- @class="new-channel-btn"- @label={{if this.site.desktopView "chat.create_channel.title"}}- />- {{/if}}- </div>+<div class="chat-browse-view__header chat-full-page-header">+ {{#if this.site.mobileView}}+ <LinkTo @route="chat.index" class="chat-full-page-header__back-btn no-text btn-flat btn" title={{i18n "chat.browse.back"}}>+ {{d-icon "chevron-left"}}+ </LinkTo>+ {{/if}}+ <span class="chat-browse-view__title">{{i18n "chat.browse.title"}}</span>++ {{#if this.currentUser.staff}}+ <DButton+ @action={{action "createChannel"}}+ @icon="plus"+ @class={{concat-class "new-channel-btn" (if this.site.mobileView "btn-flat")}}+ @label={{if this.site.desktopView "chat.create_channel.title"}}+ />+ {{/if}}+</div>++<div class="chat-browse-view"><div class="chat-browse-view__actions"><nav><ul class="nav-pills chat-browse-view__filters">diff --git a/plugins/chat/assets/javascripts/discourse/templates/components/chat-channel-row.hbs b/plugins/chat/assets/javascripts/discourse/templates/components/chat-channel-row.hbsindex ed7f03a11d1..a94cd95ada2 100644--- a/plugins/chat/assets/javascripts/discourse/templates/components/chat-channel-row.hbs+++ b/plugins/chat/assets/javascripts/discourse/templates/components/chat-channel-row.hbs@@ -1,13 +1,4 @@-<div- id="chat-channel-row-{{this.channel.id}}"- class={{this.rowClassNames}}- {{on "click" this.handleClick}}- {{on "keyup" this.handleKeyUp}}- {{on "mouseup" this.handleNewWindow}}- role="button"- tabindex="0"- data-chat-channel-id={{this.channel.id}}->+<LinkTo @route="chat.channel" @models={{array this.channel.id (or this.channel.slug "-")}} class={{this.rowClassNames}} id={{concat "chat-channel-row-" this.channel.id}} tabindex="0" data-chat-channel-id={{this.channel.id}}><ChatChannelTitle @channel={{this.channel}} @unreadIndicator={{true}} />{{#if this.showUserStatus}}@@ -25,4 +16,4 @@}}/>{{/if}}-</div>+</LinkTo>diff --git a/plugins/chat/assets/javascripts/discourse/templates/components/chat-composer.hbs b/plugins/chat/assets/javascripts/discourse/templates/components/chat-composer.hbsindex ed196e740dd..52036a87303 100644--- a/plugins/chat/assets/javascripts/discourse/templates/components/chat-composer.hbs+++ b/plugins/chat/assets/javascripts/discourse/templates/components/chat-composer.hbs@@ -45,7 +45,7 @@</div>{{#if this.canAttachUploads}}- <ChatComposerUploads @fullPage={{this.fullPage}} @fileUploadElementId={{this.fileUploadElementId}} @onUploadChanged={{action "uploadsChanged"}} />+ <ChatComposerUploads @fileUploadElementId={{this.fileUploadElementId}} @onUploadChanged={{action "uploadsChanged"}} />{{/if}}{{#unless this.chatChannel.isDraft}}diff --git a/plugins/chat/assets/javascripts/discourse/templates/components/chat-draft-channel-screen.hbs b/plugins/chat/assets/javascripts/discourse/templates/components/chat-draft-channel-screen.hbsindex d4a910e99a4..cfd2fc73911 100644--- a/plugins/chat/assets/javascripts/discourse/templates/components/chat-draft-channel-screen.hbs+++ b/plugins/chat/assets/javascripts/discourse/templates/components/chat-draft-channel-screen.hbs@@ -23,7 +23,6 @@@chatChannel={{this.previewedChannel}}@expanded={{true}}@floatHidden={{false}}- @fullPage={{true}}@includeHeader={{false}}@onSwitchChannel={{action "onSwitchFromDraftChannel"}}/>diff --git a/plugins/chat/assets/javascripts/discourse/templates/components/chat-live-pane.hbs b/plugins/chat/assets/javascripts/discourse/templates/components/chat-live-pane.hbsindex fc04885e1f8..f77e29c0b1b 100644--- a/plugins/chat/assets/javascripts/discourse/templates/components/chat-live-pane.hbs+++ b/plugins/chat/assets/javascripts/discourse/templates/components/chat-live-pane.hbs@@ -1,4 +1,4 @@-{{#if (and this.fullPage this.includeHeader)}}+{{#if (and this.chatStateManager.isFullPage this.includeHeader)}}<divclass="chat-full-page-header{{unless this.chatChannel.isFollowing "-not-following"}}"@@ -6,17 +6,17 @@<div class="chat-channel-header-details">{{#if this.site.mobileView}}<div class="chat-full-page-header__left-actions">- <DButton @class="btn-flat" @icon="chevron-left" @action={{this.onBackClick}} />+ <DButton @class="chat-full-page-header__back-btn no-text btn-flat" @icon="chevron-left" @action={{this.onBackClick}} /></div>{{/if}}- <LinkTo @route={{this.infoTabRoute}} @models={{array this.chatChannel.id (slugify-channel this.chatChannel)}} class="chat-full-page-header__title">+ <LinkTo @route={{this.infoTabRoute}} @models={{array this.chatChannel.id (slugify-channel this.chatChannel)}} class="chat-channel-title-wrapper"><ChatChannelTitle @channel={{this.chatChannel}} /></LinkTo>{{#if this.showCloseFullScreenBtn}}<div class="chat-full-page-header__right-actions">- <FlatButton @class="chat-full-screen-button" @icon="discourse-compress" @action={{action "onCloseFullScreen" this.chatChannel}} @title="chat.close_full_page" />+ <DButton @icon="discourse-compress" @title="chat.close_full_page" class="open-drawer-btn btn-flat no-text" @action={{action "onCloseFullScreen"}} /></div>{{/if}}</div>diff --git a/plugins/chat/assets/javascripts/discourse/templates/components/chat-message-actions-desktop.hbs b/plugins/chat/assets/javascripts/discourse/templates/components/chat-message-actions-desktop.hbsindex 4f8ec192932..30e1bb65a08 100644--- a/plugins/chat/assets/javascripts/discourse/templates/components/chat-message-actions-desktop.hbs+++ b/plugins/chat/assets/javascripts/discourse/templates/components/chat-message-actions-desktop.hbs@@ -1,6 +1,6 @@<div class="chat-message-actions-container" data-id={{this.message.id}}><div class="chat-message-actions">- {{#if this.chatPreferredMode.isFullPage}}+ {{#if this.chatStateManager.isFullPagePreferred}}{{#each this.emojiReactions as |reaction|}}<ChatMessageReaction @reaction={{reaction}} @react={{this.messageActions.react}} @class="show" />{{/each}}diff --git a/plugins/chat/assets/javascripts/discourse/templates/components/full-page-chat.hbs b/plugins/chat/assets/javascripts/discourse/templates/components/full-page-chat.hbsindex 42b6a72382b..72a3907e56f 100644--- a/plugins/chat/assets/javascripts/discourse/templates/components/full-page-chat.hbs+++ b/plugins/chat/assets/javascripts/discourse/templates/components/full-page-chat.hbs@@ -1,3 +1,3 @@{{#if this.chat.activeChannel}}- <ChatLivePane @chatChannel={{this.chat.activeChannel}} @expanded={{true}} @floatHidden={{false}} @fullPage={{true}} @onBackClick={{action "navigateToIndex"}} @onSwitchChannel={{action "switchChannel"}} />+ <ChatLivePane @chatChannel={{this.chat.activeChannel}} @expanded={{true}} @floatHidden={{false}} @onBackClick={{action "navigateToIndex"}} @onSwitchChannel={{action "switchChannel"}} />{{/if}}diff --git a/plugins/chat/assets/javascripts/discourse/templates/components/topic-chat-float.hbs b/plugins/chat/assets/javascripts/discourse/templates/components/topic-chat-float.hbsindex 10af503050a..2f3f5d81d4f 100644--- a/plugins/chat/assets/javascripts/discourse/templates/components/topic-chat-float.hbs+++ b/plugins/chat/assets/javascripts/discourse/templates/components/topic-chat-float.hbs@@ -11,7 +11,9 @@{{#if (and this.draftChannelView this.expanded)}}<div class="topic-chat-drawer-header__left-actions"><div class="topic-chat-drawer-header__top-line">- <FlatButton @class="topic-chat-drawer-header__return-to-channels-btn" @icon="chevron-left" @action={{action "fetchChannels"}} @title="chat.return_to_list" />+ <LinkTo title={{i18n "chat.return_to_list"}} class="topic-chat-drawer-header__return-to-channels-btn" @route="chat">+ {{d-icon "chevron-left"}}+ </LinkTo></div></div>@@ -22,9 +24,9 @@</span>{{else if this.chatView}}{{#if this.expanded}}- <div class="topic-chat-drawer-header__left-actions">- <FlatButton @class="topic-chat-drawer-header__return-to-channels-btn" @icon="chevron-left" @action={{action "fetchChannels"}} @title="chat.return_to_list" />- </div>+ <LinkTo title={{i18n "chat.return_to_list"}} class="topic-chat-drawer-header__return-to-channels-btn" @route="chat">+ {{d-icon "chevron-left"}}+ </LinkTo>{{/if}}{{#if this.chat.activeChannel}}@@ -57,15 +59,7 @@<div class="topic-chat-drawer-header__right-actions"><div class="topic-chat-drawer-header__top-line {{this.topLineClass}}">{{#if this.expanded}}- <button- class="btn-flat topic-chat-drawer-header__full-screen-btn"- onmouseup={{action "openInFullPage"}}- icon="discourse-expand"- title={{i18n "chat.open_full_page"}}- type="button"- >- {{d-icon "discourse-expand"}}- </button>+ <DButton @icon="discourse-expand" class="btn-flat btn-link topic-chat-drawer-header__full-screen-btn" @title={{"chat.open_full_page"}} @action={{this.openInFullPage}} />{{/if}}<FlatButton @icon={{this.expandIcon}} @class="topic-chat-drawer-header__expand-btn" @action={{action "toggleExpand"}} @title="chat.collapse" />@@ -80,11 +74,11 @@{{#if this.expanded}}<div class="topic-chat-drawer-content">{{#if (and this.chatView this.chat.activeChannel)}}- <ChatLivePane @chatChannel={{this.chat.activeChannel}} @expanded={{this.expanded}} @floatHidden={{this.hidden}} @fullPage={{false}} @onSwitchChannel={{action "switchChannel"}} />+ <ChatLivePane @chatChannel={{this.chat.activeChannel}} @expanded={{this.expanded}} @floatHidden={{this.hidden}} @onSwitchChannel={{action "switchChannel"}} />{{else if this.draftChannelView}}<ChatDraftChannelScreen @onSwitchChannel={{action "switchChannel"}} />{{else}}- <ChannelsList @floatHidden={{this.hidden}} @onOpenView={{action "openView"}} @onSelect={{action "switchChannel"}} />+ <ChannelsList @floatHidden={{this.hidden}} @onOpenView={{action "openURL"}} @onSelect={{action "switchChannel"}} />{{/if}}</div>{{/if}}diff --git a/plugins/chat/assets/javascripts/discourse/widgets/chat-header-icon.js b/plugins/chat/assets/javascripts/discourse/widgets/chat-header-icon.jsindex 215c382f45c..39e1b768d38 100644--- a/plugins/chat/assets/javascripts/discourse/widgets/chat-header-icon.js+++ b/plugins/chat/assets/javascripts/discourse/widgets/chat-header-icon.js@@ -8,7 +8,7 @@ export default createWidget("header-chat-link", {chat: null,tagName: "li.header-dropdown-toggle.open-chat",title: "chat.title",- services: ["chat", "router", "chatPreferredMode", "fullPageChat"],+ services: ["chat", "router", "chatStateManager"],html() {if (!this.chat.userCanChat) {@@ -40,7 +40,7 @@ export default createWidget("header-chat-link", {chatLinkHtml(indicatorNode) {return h(`a.icon${- this.fullPageChat.isActive || this.chat.chatOpen ? ".active" : ""+ this.chatStateManager.isFullPage || this.chat.chatOpen ? ".active" : ""}`,{ attributes: { tabindex: 0 } },[iconNode("comment"), indicatorNode].filter(Boolean)@@ -61,20 +61,13 @@ export default createWidget("header-chat-link", {},click() {- if (this.fullPageChat.isActive && !this.site.mobileView) {+ if (this.chatStateManager.isFullPage && !this.site.mobileView) {return;}- if (- this.chat.sidebarActive ||- this.site.mobileView ||- this.chatPreferredMode.isFullPage- ) {- this.chatPreferredMode.setFullPage();- return this.router.transitionTo("chat");- } else {- this.appEvents.trigger("chat:toggle-open");- }+ return this.router.transitionTo(+ this.chatStateManager.lastKnownChatURL || "chat"+ );},chatRerenderHeader() {diff --git a/plugins/chat/assets/javascripts/discourse/widgets/topic-chat-button.js b/plugins/chat/assets/javascripts/discourse/widgets/topic-chat-button.jsdeleted file mode 100644index 9bb7f2674f4..00000000000--- a/plugins/chat/assets/javascripts/discourse/widgets/topic-chat-button.js+++ /dev/null@@ -1,22 +0,0 @@-import hbs from "discourse/widgets/hbs-compiler";-import { createWidget } from "discourse/widgets/widget";-import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel";--export default createWidget("topic-chat-button", {- tagName: "button.btn.btn-default.topic-chat-button",- title: "chat.open",-- click() {- this.appEvents.trigger(- "chat:open-channel-for-chatable",- ChatChannel.create(this.attrs.chat_channel)- );- },-- template: hbs`- {{d-icon "far-comments"}}- <span class="label">- {{i18n "chat.topic_button_title"}}- </span>- `,-});diff --git a/plugins/chat/assets/stylesheets/common/chat-browse.scss b/plugins/chat/assets/stylesheets/common/chat-browse.scssindex 82dd07d4c7a..cb529249ba1 100644--- a/plugins/chat/assets/stylesheets/common/chat-browse.scss+++ b/plugins/chat/assets/stylesheets/common/chat-browse.scss@@ -10,9 +10,13 @@&__header {display: flex;- gap: 1rem;align-items: center;- margin: 1rem 0 1rem 1rem;+ justify-content: flex-start;+ margin-bottom: 1em;++ .new-channel-btn {+ margin-left: auto;+ }}&__title {@@ -29,10 +33,6 @@}}- .new-channel-btn {- margin-left: auto;- }-&__cards {display: grid;grid-template-columns: repeat(2, 1fr);diff --git a/plugins/chat/assets/stylesheets/common/chat-channel-info.scss b/plugins/chat/assets/stylesheets/common/chat-channel-info.scssindex 67985b146b5..2a6c5c1fd19 100644--- a/plugins/chat/assets/stylesheets/common/chat-channel-info.scss+++ b/plugins/chat/assets/stylesheets/common/chat-channel-info.scss@@ -2,11 +2,6 @@display: flex;flex-direction: column;height: 100%;-- &__back-btn {- font-size: var(--font-down-1);- margin: 0 0 1rem 0;- }}// Info header@@ -18,11 +13,6 @@box-sizing: border-box;}-.channel-info__back-btn {- margin-bottom: 1rem;- display: block;-}-.channel-info-header__title {font-size: var(--font-up-2);margin: 0;diff --git a/plugins/chat/assets/stylesheets/common/chat-channel-title.scss b/plugins/chat/assets/stylesheets/common/chat-channel-title.scssindex a9cf778cc4b..f5043f4d799 100644--- a/plugins/chat/assets/stylesheets/common/chat-channel-title.scss+++ b/plugins/chat/assets/stylesheets/common/chat-channel-title.scss@@ -1,3 +1,8 @@+.chat-channel-title-wrapper {+ display: flex;+ align-items: center;+}+.chat-channel-title {display: flex;align-items: center;diff --git a/plugins/chat/assets/stylesheets/common/chat-drawer.scss b/plugins/chat/assets/stylesheets/common/chat-drawer.scssindex 06421a7026a..e996f96790e 100644--- a/plugins/chat/assets/stylesheets/common/chat-drawer.scss+++ b/plugins/chat/assets/stylesheets/common/chat-drawer.scss@@ -91,6 +91,7 @@ body.composer-open .topic-chat-float-container {.topic-chat-drawer-header__right-actions {display: flex;height: 100%;+ margin-left: auto;}.topic-chat-drawer-header__top-line {@@ -172,13 +173,27 @@ body.composer-open .topic-chat-float-container {}}- &__return-to-channels-btn,&__close-btn,+ &__return-to-channels-btn,&__full-screen-btn,&__expand-btn {- height: 100%;max-height: 2.5rem;- width: 2.5rem;+ height: 100%;+ min-width: 40px;+ width: 40px;+ display: flex;+ justify-content: center;+ align-items: center;++ .d-icon {+ color: var(--primary-low-mid);+ }++ &:visited {+ .d-icon {+ color: var(--primary-low-mid);+ }+ }&:focus {outline: none;diff --git a/plugins/chat/assets/stylesheets/common/common.scss b/plugins/chat/assets/stylesheets/common/common.scssindex ba8be09a786..a12e0b21bba 100644--- a/plugins/chat/assets/stylesheets/common/common.scss+++ b/plugins/chat/assets/stylesheets/common/common.scss@@ -149,8 +149,8 @@ $float-height: 530px;}}- .edit-channel-membership-btn,- .new-dm,+ .open-browse-page-btn,+ .open-draft-channel-page-btn,.chat-channel-leave-btn {background: transparent;color: var(--primary-medium);@@ -202,7 +202,7 @@ $float-height: 530px;}}}- .edit-channel-membership-btn {+ .open-browse-page-btn {&:hover {background: none;}@@ -318,6 +318,22 @@ $float-height: 530px;min-height: 1px;position: relative;+ .open-drawer-btn {+ color: var(--primary-low-mid);++ &:visited {+ color: var(--primary-low-mid);+ }++ &:hover {+ color: var(--primary);+ }++ > * {+ pointer-events: none;+ }+ }+.chat-messages-scroll {flex-grow: 1;overflow-y: scroll;@@ -419,6 +435,10 @@ $float-height: 530px;transition: opacity 50ms ease-in;opacity: 1;+ .chat-user-avatar {+ pointer-events: none;+ }+.chat-channel-unread-indicator {margin-left: 0.5rem;}@@ -629,6 +649,16 @@ body.has-full-page-chat {border-bottom: 1px solid var(--primary-low);background: var(--secondary);z-index: 3;+ display: flex;+ align-items: center;++ &__back-btn {+ width: 40px;+ min-width: 40px;+ display: flex;+ align-items: center;+ justify-content: center;+ }.chat-channel-title {.category-chat-name,@@ -680,9 +710,12 @@ body.has-full-page-chat {}.chat-full-page-header {+ box-sizing: border-box;+.chat-channel-header-details {display: flex;align-items: stretch;+ flex: 1;.chat-channel-archive-status {text-align: right;diff --git a/plugins/chat/assets/stylesheets/common/direct-message-creator.scss b/plugins/chat/assets/stylesheets/common/direct-message-creator.scssindex b7c6e5989a7..02444815adf 100644--- a/plugins/chat/assets/stylesheets/common/direct-message-creator.scss+++ b/plugins/chat/assets/stylesheets/common/direct-message-creator.scss@@ -178,11 +178,11 @@.no-results {text-align: center;padding: 1rem;- position: absolute;width: 100%;box-shadow: shadow("card");background: var(--secondary);margin: 0;+ box-sizing: border-box;}.fetching-preview-message {diff --git a/plugins/chat/assets/stylesheets/desktop/chat-channel-title.scss b/plugins/chat/assets/stylesheets/desktop/chat-channel-title.scssindex e127cbe8d41..5c79ad4b616 100644--- a/plugins/chat/assets/stylesheets/desktop/chat-channel-title.scss+++ b/plugins/chat/assets/stylesheets/desktop/chat-channel-title.scss@@ -1,3 +1,12 @@+.chat-channel-title-wrapper {+ padding: 0.25rem;++ &:hover {+ background: var(--primary-very-low);+ border-radius: 5px;+ }+}+.channels-list {.chat-channel-title {max-width: 100%;diff --git a/plugins/chat/assets/stylesheets/desktop/desktop.scss b/plugins/chat/assets/stylesheets/desktop/desktop.scssindex fa1cb31d43a..f5175f9638d 100644--- a/plugins/chat/assets/stylesheets/desktop/desktop.scss+++ b/plugins/chat/assets/stylesheets/desktop/desktop.scss@@ -18,7 +18,9 @@}.chat-full-page-header {- padding: 1rem;+ padding: 0 1rem;+ height: 65px;+ min-height: 65px;flex-shrink: 0;}diff --git a/plugins/chat/assets/stylesheets/mobile/chat-channel-info.scss b/plugins/chat/assets/stylesheets/mobile/chat-channel-info.scssindex c23348aeb8d..e69de29bb2d 100644--- a/plugins/chat/assets/stylesheets/mobile/chat-channel-info.scss+++ b/plugins/chat/assets/stylesheets/mobile/chat-channel-info.scss@@ -1,5 +0,0 @@-.channel-info {- &__back-btn {- margin: 0.5rem 0 1rem 0;- }-}diff --git a/plugins/chat/assets/stylesheets/mobile/chat-index.scss b/plugins/chat/assets/stylesheets/mobile/chat-index.scssindex 9445dd2eb44..2a037ac1715 100644--- a/plugins/chat/assets/stylesheets/mobile/chat-index.scss+++ b/plugins/chat/assets/stylesheets/mobile/chat-index.scss@@ -92,7 +92,7 @@}}- .btn-floating.new-dm {+ .btn-floating.open-draft-channel-page-btn {position: absolute;background: var(--tertiary);bottom: 2.5rem;diff --git a/plugins/chat/assets/stylesheets/mobile/mobile.scss b/plugins/chat/assets/stylesheets/mobile/mobile.scssindex 4a352f1f44f..a01476f5202 100644--- a/plugins/chat/assets/stylesheets/mobile/mobile.scss+++ b/plugins/chat/assets/stylesheets/mobile/mobile.scss@@ -43,6 +43,15 @@ body.has-full-page-chat {overflow-x: hidden;width: 100%;+ .btn:active,+ .btn:hover {+ background: var(--secondary-very-high);++ .d-icon {+ color: var(--primary-medium);+ }+ }+.chat-live-pane {border-radius: 0;padding: 0;@@ -54,7 +63,9 @@ body.has-full-page-chat {.chat-full-page-header {background-color: var(--secondary);- padding: 0.5em 10px;+ padding: 0 10px;+ height: 50px;+ min-height: 50px;}.chat-messages-scroll {diff --git a/plugins/chat/assets/stylesheets/sidebar-extensions.scss b/plugins/chat/assets/stylesheets/sidebar-extensions.scssindex e81e2f8b602..74d8b9210d1 100644--- a/plugins/chat/assets/stylesheets/sidebar-extensions.scss+++ b/plugins/chat/assets/stylesheets/sidebar-extensions.scss@@ -77,8 +77,8 @@}}- .new-dm,- .edit-channel-membership-btn,+ .open-draft-channel-page-btn,+ .open-browse-page-btn,.edit-channels-dropdown .select-kit-header,.chat-channel-leave-btn {display: flex;diff --git a/plugins/chat/config/locales/client.en.yml b/plugins/chat/config/locales/client.en.ymlindex af7167e0520..1b492d7a7bb 100644--- a/plugins/chat/config/locales/client.en.yml+++ b/plugins/chat/config/locales/client.en.yml@@ -375,8 +375,6 @@ en:public: "Channel history is retained for %{days} days."dm: "Personal chat history is retained for %{days} days."- topic_button_title: "Chat"-flags:off_topic: "This message is not relevant to the current discussion as defined by the channel title, and should probably be moved elsewhere."inappropriate: "This message contains content that a reasonable person would consider offensive, abusive, or a violation of <a href=\"%{basePath}/guidelines\">our community guidelines</a>."diff --git a/plugins/chat/plugin.rb b/plugins/chat/plugin.rbindex ab32fcd0c18..1c76b232745 100644--- a/plugins/chat/plugin.rb+++ b/plugins/chat/plugin.rb@@ -20,7 +20,6 @@ register_asset "stylesheets/common/chat-drawer.scss"register_asset "stylesheets/mobile/chat-index.scss", :mobileregister_asset "stylesheets/common/chat-channel-preview-card.scss"register_asset "stylesheets/common/chat-channel-info.scss"-register_asset "stylesheets/mobile/chat-channel-info.scss", :mobileregister_asset "stylesheets/common/chat-draft-channel.scss"register_asset "stylesheets/common/chat-tabs.scss"register_asset "stylesheets/common/chat-form.scss"diff --git a/plugins/chat/spec/system/navigation_spec.rb b/plugins/chat/spec/system/navigation_spec.rbindex 5438cebc7d4..27818332e88 100644--- a/plugins/chat/spec/system/navigation_spec.rb+++ b/plugins/chat/spec/system/navigation_spec.rb@@ -6,9 +6,11 @@ RSpec.describe "Navigation", type: :system, js: true dofab!(:post) { Fabricate(:post, topic: topic) }fab!(:user) { Fabricate(:admin) }fab!(:category_channel) { Fabricate(:category_channel) }+ fab!(:category_channel_2) { Fabricate(:category_channel) }fab!(:message) { Fabricate(:chat_message, chat_channel: category_channel) }let(:chat_page) { PageObjects::Pages::Chat.new }let(:sidebar_page) { PageObjects::Pages::Sidebar.new }+ let(:chat_drawer_page) { PageObjects::Pages::ChatDrawer.new }before do# ensures we have one valid registered admin@@ -17,13 +19,14 @@ RSpec.describe "Navigation", type: :system, js: true doSiteSetting.chat_enabled = trueSiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:everyone]category_channel.add(user)+ category_channel_2.add(user)sign_in(user)endcontext "when visiting /chat" doit "opens full page" do- chat_page.open_full_page+ chat_page.openexpect(page).to have_current_path(chat.channel_path(category_channel.id, category_channel.slug),@@ -46,7 +49,7 @@ RSpec.describe "Navigation", type: :system, js: true doit "opens the full page" dovisit("/")chat_page.open_from_header- chat_page.maximize_drawer+ chat_drawer_page.maximizeexpect(page).to have_current_path(chat.channel_path(category_channel.id, category_channel.slug),@@ -63,7 +66,7 @@ RSpec.describe "Navigation", type: :system, js: true docontext "when opening chat with drawer as preferred mode" doit "opens the full page" do- chat_page.open_full_page+ chat_page.openchat_page.minimize_full_pageexpect(page).to have_css(".topic-chat-container.expanded.visible")@@ -77,7 +80,7 @@ RSpec.describe "Navigation", type: :system, js: true docontext "when collapsing full page with no previous state" doit "redirects to home page" do- chat_page.open_full_page+ chat_page.openchat_page.minimize_full_pageexpect(page).to have_current_path(latest_path)@@ -88,7 +91,7 @@ RSpec.describe "Navigation", type: :system, js: true doit "redirects to previous state" dovisit("/t/-/#{topic.id}")chat_page.open_from_header- chat_page.maximize_drawer+ chat_drawer_page.maximizechat_page.minimize_full_pageexpect(page).to have_current_path("/t/#{topic.slug}/#{topic.id}")@@ -106,7 +109,7 @@ RSpec.describe "Navigation", type: :system, js: true doit "opens channel in drawer" dovisit("/t/-/#{topic.id}")chat_page.open_from_header- chat_page.close_drawer+ chat_drawer_page.closefind("a[title='#{category_channel.title}']").clickexpect(page).to have_css(".chat-message-container[data-id='#{message.id}']")@@ -117,7 +120,7 @@ RSpec.describe "Navigation", type: :system, js: true doit "opens channel in full page" dovisit("/")chat_page.open_from_header- chat_page.maximize_drawer+ chat_drawer_page.maximizevisit("/")find("a[title='#{category_channel.title}']").click@@ -130,10 +133,21 @@ RSpec.describe "Navigation", type: :system, js: true docontext "when starting draft from sidebar with drawer preferred" doit "opens draft in drawer" dovisit("/")- sidebar_page.start_draft_dm+ sidebar_page.open_draft_channelexpect(page).to have_current_path("/")- expect(page).to have_css(".topic-chat-container.expanded.visible")+ expect(page).to have_css(".topic-chat-container.expanded.visible .direct-message-creator")+ end+ end++ context "when starting draft from drawer with drawer preferred" do+ it "opens draft in drawer" do+ visit("/")+ chat_page.open_from_header+ chat_drawer_page.open_draft_channel++ expect(page).to have_current_path("/")+ expect(page).to have_css(".topic-chat-container.expanded.visible .direct-message-creator")endend@@ -141,13 +155,66 @@ RSpec.describe "Navigation", type: :system, js: true doit "opens draft in full page" dovisit("/")chat_page.open_from_header- chat_page.maximize_drawer+ chat_drawer_page.maximizevisit("/")- sidebar_page.start_draft_dm+ sidebar_page.open_draft_channelexpect(page).to have_current_path("/chat/draft-channel")expect(page).not_to have_css(".topic-chat-container.expanded.visible")endend++ context "when opening browse page from drawer in drawer mode" do+ it "opens browser page in full page" do+ visit("/")+ chat_page.open_from_header+ chat_drawer_page.open_browse++ expect(page).to have_current_path("/chat/browse/open")+ expect(page).not_to have_css(".topic-chat-container.expanded.visible")+ end+ end++ context "when opening browse page from sidebar in drawer mode" do+ it "opens browser page in full page" do+ visit("/")+ chat_page.open_from_header+ sidebar_page.open_browse++ expect(page).to have_current_path("/chat/browse/open")+ expect(page).not_to have_css(".topic-chat-container.expanded.visible")+ end+ end++ context "when re-opening drawer after navigating to a channel" do+ it "opens drawer on correct channel" do+ visit("/")+ chat_page.open_from_header+ chat_drawer_page.open_channel(category_channel_2)+ chat_drawer_page.open_index+ chat_drawer_page.close+ chat_page.open_from_header++ expect(page).to have_current_path("/")+ expect(page).to have_css(".topic-chat-container.expanded.visible")+ expect(page).to have_content(category_channel_2.title)+ end+ end++ context "when re-opening full page chat after navigating to a channel" do+ it "opens full page chat on correct channel" do+ visit("/")+ chat_page.open_from_header+ chat_drawer_page.maximize+ sidebar_page.open_channel(category_channel_2)+ find("#site-logo").click+ chat_page.open_from_header++ expect(page).to have_current_path(+ chat.channel_path(category_channel_2.id, category_channel_2.slug),+ )+ expect(page).to have_content(category_channel_2.title)+ end+ endendenddiff --git a/plugins/chat/spec/system/page_objects/chat/chat.rb b/plugins/chat/spec/system/page_objects/chat/chat.rbindex bed05c97bd6..43c1529cd8a 100644--- a/plugins/chat/spec/system/page_objects/chat/chat.rb+++ b/plugins/chat/spec/system/page_objects/chat/chat.rb@@ -7,20 +7,12 @@ module PageObjectsfind(".open-chat").clickend- def open_full_page+ def openvisit("/chat")end- def maximize_drawer- find(".topic-chat-drawer-header__full-screen-btn").click- end-- def close_drawer- find(".topic-chat-drawer-header__close-btn").click- end-def minimize_full_page- find(".chat-full-screen-button").click+ find(".open-drawer-btn").clickendendenddiff --git a/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rb b/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rbnew file mode 100644index 00000000000..5e2cae079d7--- /dev/null+++ b/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rb@@ -0,0 +1,34 @@+# frozen_string_literal: true++module PageObjects+ module Pages+ class ChatDrawer < PageObjects::Pages::Base+ VISIBLE_DRAWER = ".topic-chat-container.expanded.visible"+ def open_browse+ find("#{VISIBLE_DRAWER} .open-browse-page-btn").click+ end++ def open_draft_channel+ find("#{VISIBLE_DRAWER} .open-draft-channel-page-btn").click+ end++ def close+ find("#{VISIBLE_DRAWER} .topic-chat-drawer-header__close-btn").click+ end++ def open_index+ find("#{VISIBLE_DRAWER} .topic-chat-drawer-header__return-to-channels-btn").click+ end++ def open_channel(channel)+ find(+ "#{VISIBLE_DRAWER} .channels-list .chat-channel-row[data-chat-channel-id='#{channel.id}']",+ ).click+ end++ def maximize+ find("#{VISIBLE_DRAWER} .topic-chat-drawer-header__full-screen-btn").click+ end+ end+ end+enddiff --git a/plugins/chat/spec/system/page_objects/sidebar/sidebar.rb b/plugins/chat/spec/system/page_objects/sidebar/sidebar.rbindex b9633001c20..e7786fafc90 100644--- a/plugins/chat/spec/system/page_objects/sidebar/sidebar.rb+++ b/plugins/chat/spec/system/page_objects/sidebar/sidebar.rb@@ -3,9 +3,17 @@module PageObjectsmodule Pagesclass Sidebar < PageObjects::Pages::Base- def start_draft_dm+ def open_draft_channelfind(".sidebar-section-chat-dms .sidebar-section-header-button", visible: false).clickend++ def open_browse+ find(".sidebar-section-chat-channels .sidebar-section-header-button", visible: false).click+ end++ def open_channel(channel)+ find(".sidebar-section-link[href='/chat/channel/#{channel.id}/#{channel.slug}']").click+ endendendenddiff --git a/plugins/chat/test/javascripts/acceptance/chat-composer-test.js b/plugins/chat/test/javascripts/acceptance/chat-composer-test.jsindex cb603048309..4fd59c33341 100644--- a/plugins/chat/test/javascripts/acceptance/chat-composer-test.js+++ b/plugins/chat/test/javascripts/acceptance/chat-composer-test.js@@ -136,7 +136,6 @@ acceptance("Discourse Chat - Composer - unreliable network", function (needs) {});test("Sending a message with unreliable network", async function (assert) {- this.chatService.set("chatWindowFullPage", false);await visit("/chat/channel/11/-");await fillIn(".chat-composer-input", "network-error-message");await click(".send-btn");@@ -174,7 +173,6 @@ acceptance("Discourse Chat - Composer - unreliable network", function (needs) {});test("Draft with unreliable network", async function (assert) {- this.chatService.set("chatWindowFullPage", false);await visit("/chat/channel/11/-");this.chatService.set("isNetworkUnreliable", true);await settled();diff --git a/plugins/chat/test/javascripts/acceptance/chat-keyboard-shortcuts-test.js b/plugins/chat/test/javascripts/acceptance/chat-keyboard-shortcuts-test.jsindex ec8e0389728..cde51fdd3ba 100644--- a/plugins/chat/test/javascripts/acceptance/chat-keyboard-shortcuts-test.js+++ b/plugins/chat/test/javascripts/acceptance/chat-keyboard-shortcuts-test.js@@ -165,9 +165,10 @@ acceptance("Discourse Chat - Keyboard shortcuts", function (needs) {test("switching channel with alt+arrow keys in float", async function (assert) {await visit("/latest");this.chatService.set("sidebarActive", false);- this.chatService.set("chatWindowFullPage", false);await click(".header-dropdown-toggle.open-chat");+ await click("#chat-channel-row-4");+assert.ok(visible(".topic-chat-float-container"), "chat float is open");assert.ok(query(".topic-chat-container").classList.contains("channel-4"));@@ -184,9 +185,10 @@ acceptance("Discourse Chat - Keyboard shortcuts", function (needs) {});test("simple composer formatting shortcuts", async function (assert) {- await visit("/latest");this.chatService.set("sidebarActive", false);+ await visit("/latest");await click(".header-dropdown-toggle.open-chat");+ await click(".chat-channel-row");const composerInput = query(".chat-composer-input");await fillIn(composerInput, "test text");@@ -230,6 +232,7 @@ acceptance("Discourse Chat - Keyboard shortcuts", function (needs) {this.chatService.set("sidebarActive", false);await click(".header-dropdown-toggle.open-chat");+ await click(".chat-channel-row");await fillIn(".chat-composer-input", stagedMessageText);await click(".chat-composer-inline-button");await triggerKeyEvent(".chat-composer-input", "keydown", "ArrowUp");@@ -245,6 +248,7 @@ acceptance("Discourse Chat - Keyboard shortcuts", function (needs) {this.chatService.set("sidebarActive", false);await click(".header-dropdown-toggle.open-chat");+ await click(".chat-channel-row");await focus(".chat-composer-input");await fillIn(".chat-composer-input", "This is a link to ");@@ -275,17 +279,16 @@ acceptance("Discourse Chat - Keyboard shortcuts", function (needs) {test("Dash key (-) opens chat float", async function (assert) {await visit("/latest");this.chatService.set("sidebarActive", false);- this.chatService.set("chatWindowFullPage", false);await triggerKeyEvent(document.body, "keydown", "-");assert.ok(exists(".topic-chat-drawer-content"), "chat float is open");});test("Pressing Escape when drawer is opened", async function (assert) {- await visit("/latest");this.chatService.set("sidebarActive", false);- this.chatService.set("chatWindowFullPage", false);+ await visit("/latest");await click(".header-dropdown-toggle.open-chat");+ await click(".chat-channel-row");const composerInput = query(".chat-composer-input");await focus(composerInput);@@ -299,7 +302,6 @@ acceptance("Discourse Chat - Keyboard shortcuts", function (needs) {test("Pressing Escape when full page is opened", async function (assert) {this.chatService.set("sidebarActive", false);- this.chatService.set("chatWindowFullPage", true);await visit("/chat/channel/75/@hawk");const composerInput = query(".chat-composer-input");await focus(composerInput);diff --git a/plugins/chat/test/javascripts/acceptance/chat-test.js b/plugins/chat/test/javascripts/acceptance/chat-test.jsindex 90235ce2e85..d1f6e5346fb 100644--- a/plugins/chat/test/javascripts/acceptance/chat-test.js+++ b/plugins/chat/test/javascripts/acceptance/chat-test.js@@ -141,7 +141,6 @@ acceptance("Discourse Chat - without unread", function (needs) {// TODO: needs a future change to how we handle URLS to be possibleskip("Clicking mention notification from outside chat opens the float", async function (assert) {- this.chatService.set("chatWindowFullPage", false);await visit("/t/internationalization-localization/280");await click(".header-dropdown-toggle.current-user");await click("#quick-access-notifications .chat-mention");@@ -226,9 +225,9 @@ acceptance("Discourse Chat - without unread", function (needs) {"it doesn’t show the rebake button for non staff");- await visit("/");updateCurrentUser({ admin: true, moderator: true });- await visit("/chat/channel/11/another-category");+ await visit("/chat");+await triggerEvent(".chat-message-container[data-id='174']", "mouseenter");await currentUserDropdown.expand();@@ -368,9 +367,10 @@ acceptance("Discourse Chat - without unread", function (needs) {test("Reply-to is stored in draft", async function (assert) {this.chatService.set("sidebarActive", false);- this.chatService.set("chatWindowFullPage", false);+await visit("/latest");- this.appEvents.trigger("chat:toggle-open");+ await click(".header-dropdown-toggle.open-chat");+ await click(".chat-channel-row");await settled();await click(".topic-chat-drawer-header__return-to-channels-btn");@@ -708,7 +708,7 @@ Widget.triangulate(arg: "test")test("creating a new direct message channel works", async function (assert) {await visit("/chat/channel/11/another-category");- await click(".new-dm");+ await click(".open-draft-channel-page-btn");await fillIn(".filter-usernames", "hawk");await click("li.user[data-username='hawk']");@@ -726,7 +726,7 @@ Widget.triangulate(arg: "test")test("creating a new direct message channel from popup chat works", async function (assert) {await visit("/t/internationalization-localization/280");- await click(".new-dm");+ await click(".open-draft-channel-page-btn");await fillIn(".filter-usernames", "hawk");await click('.chat-user-avatar-container[data-user-card="hawk"]');assert.ok(query(".selected-user").innerText, "hawk");@@ -979,31 +979,10 @@ acceptance(test("Expand button takes you to full page chat on the correct channel", async function (assert) {await visit("/t/internationalization-localization/280");this.chatService.set("sidebarActive", false);- await visit(".header-dropdown-toggle.open-chat");- await click(".topic-chat-drawer-header__full-screen-btn");-- assert.equal(currentURL(), `/chat/channel/11/another-category`);- });-- test("Chat opens to full-page channel with unread messages when sidebar is installed", async function (assert) {- await visit("/t/internationalization-localization/280");- this.chatService.set("sidebarActive", true);-await click(".header-dropdown-toggle.open-chat");+ await click(".topic-chat-drawer-header__full-screen-btn");assert.equal(currentURL(), `/chat/channel/11/another-category`);- assert.notOk(- visible(".topic-chat-float-container"),- "chat float is not open"- );- });-- test("Chat float opens on header icon click when sidebar is not installed", async function (assert) {- await visit("/t/internationalization-localization/280");- this.chatService.set("sidebarActive", false);- this.chatService.set("chatWindowFullPage", false);- await click(".header-dropdown-toggle.open-chat");- assert.ok(visible(".topic-chat-float-container"), "chat float is open");});test("Unread header indicator is present", async function (assert) {@@ -1047,7 +1026,7 @@ acceptance(test("Close fullscreen chat button present", async function (assert) {await visit("/chat/channel/11/another-category");- assert.ok(exists(".chat-full-screen-button"));+ assert.ok(exists(".open-drawer-btn"));});});@@ -1110,6 +1089,7 @@ acceptance(visible(".topic-chat-drawer-header__top-line--expanded"),"chat float is expanded");+ await click("#chat-channel-row-9");await click(".topic-chat-drawer-header__title");assert.equal(currentURL(), `/chat/channel/9/site/info/members`);});@@ -1118,16 +1098,22 @@ acceptance(await visit("/t/internationalization-localization/280");this.chatService.set("sidebarActive", false);await click(".header-dropdown-toggle.open-chat");+ await click(".chat-channel-row");+assert.ok(visible(".topic-chat-drawer-header__top-line--expanded"),"chat float is expanded");+await click(".topic-chat-drawer-header__expand-btn");+assert.ok(visible(".topic-chat-drawer-header__top-line--collapsed"),"chat float is collapsed");+await click(".topic-chat-drawer-header__title");+assert.ok(visible(".topic-chat-drawer-header__top-line--expanded"),"chat float is expanded"@@ -1181,14 +1167,16 @@ acceptance(test("Chat float open to DM channel with unread messages with sidebar off", async function (assert) {await visit("/t/internationalization-localization/280");this.chatService.set("sidebarActive", false);- this.chatService.set("chatWindowFullPage", false);+await click(".header-dropdown-toggle.open-chat");+ await click("#chat-channel-row-75");const chatContainer = query(".topic-chat-container");assert.ok(chatContainer.classList.contains("channel-75"));});test("Chat full page open to DM channel with unread messages with sidebar on", async function (assert) {this.chatService.set("sidebarActive", true);+ this.owner.lookup("service:chat-state-manager").prefersFullPage();await visit("/t/internationalization-localization/280");await click(".header-dropdown-toggle.open-chat");@@ -1248,8 +1236,6 @@ acceptance(});test("Create channel modal", async function (assert) {- this.container.lookup("service:chat").set("chatWindowFullPage", true);-await visit("/chat/browse");await click(".new-channel-btn");@@ -1415,7 +1401,6 @@ acceptance("Discourse Chat - image uploads", function (needs) {test("uploading files in chat works", async function (assert) {await visit("/t/internationalization-localization/280");this.container.lookup("service:chat").set("sidebarActive", false);- this.container.lookup("service:chat").set("chatWindowFullPage", false);await click(".header-dropdown-toggle.open-chat");assert.ok(visible(".topic-chat-float-container"), "chat float is open");@@ -1475,8 +1460,8 @@ acceptance("Discourse Chat - image uploads", function (needs) {assert.ok(exists(".d-editor-input"), "the composer input is visible");this.container.lookup("service:chat").set("sidebarActive", false);- this.container.lookup("service:chat").set("chatWindowFullPage", false);await click(".header-dropdown-toggle.open-chat");+ await click(".chat-channel-row");assert.ok(visible(".topic-chat-float-container"), "chat float is open");const appEvents = loggedInUser().appEvents;@@ -1816,12 +1801,12 @@ acceptance("Discourse Chat - Direct Message Creator", function (needs) {test("Create a direct message", async function (assert) {await visit("/latest");await click(".header-dropdown-toggle.open-chat");- await click(".topic-chat-drawer-header__return-to-channels-btn");+assert.ok(- !exists(".new-dm.btn-floating"),+ !exists(".open-draft-channel-page-btn.btn-floating"),"mobile floating button should not exist on desktop");- await click(".btn.new-dm");+ await click(".btn.open-draft-channel-page-btn");assert.ok(exists(".chat-draft"), "view changes to draft channel screen");});});@@ -1841,8 +1826,6 @@ acceptance("Discourse Chat - Drawer", function (needs) {});test("Position after closing reduced composer", async function (assert) {- this.chatService.set("chatWindowFullPage", false);-await visit("/t/internationalization-localization/280");await click(".btn.create");await click(".toggle-preview");diff --git a/plugins/chat/test/javascripts/acceptance/mobile-chat-test.js b/plugins/chat/test/javascripts/acceptance/mobile-chat-test.jsindex 935e4ccae8a..62db7c85bbe 100644--- a/plugins/chat/test/javascripts/acceptance/mobile-chat-test.js+++ b/plugins/chat/test/javascripts/acceptance/mobile-chat-test.js@@ -40,12 +40,13 @@ acceptance("Discourse Chat - Mobile test", function (needs) {assert.equal(currentURL(), "/chat");assert.ok(exists(".channels-list"));await click(".chat-channel-row.chat-channel-7");- assert.notOk(exists(".chat-full-screen-button"));+ assert.notOk(exists(".open-drawer-btn"));});test("Chat new personal chat buttons", async function (assert) {await visit("/chat");- await click(".new-dm.btn-floating");+ await click(".open-draft-channel-page-btn.btn-floating");+assert.strictEqual(currentURL(),"/chat/draft-channel",@@ -53,6 +54,7 @@ acceptance("Discourse Chat - Mobile test", function (needs) {);await click(".chat-draft-header__btn");+assert.strictEqual(currentURL(),"/chat",@@ -62,7 +64,8 @@ acceptance("Discourse Chat - Mobile test", function (needs) {test("Chat browse screen back button", async function (assert) {await visit("/chat/browse");- await click(".chat-browse-view__back");+ await click(".chat-full-page-header__back-btn");+assert.strictEqual(currentURL(),"/chat",diff --git a/plugins/chat/test/javascripts/acceptance/nagivation-scenarios-test.js b/plugins/chat/test/javascripts/acceptance/nagivation-scenarios-test.jsdeleted file mode 100644index 5499e42239e..00000000000--- a/plugins/chat/test/javascripts/acceptance/nagivation-scenarios-test.js+++ /dev/null@@ -1,39 +0,0 @@-import {- acceptance,- loggedInUser,-} from "discourse/tests/helpers/qunit-helpers";-import { click, currentURL, visit } from "@ember/test-helpers";-import { generateChatView } from "discourse/plugins/chat/chat-fixtures";-import { test } from "qunit";-import fabricators from "../helpers/fabricators";--acceptance("Discourse Chat - Navigation scenarios", function (needs) {- needs.user({ can_chat: true, has_chat_enabled: true });-- needs.settings({ chat_enabled: true });-- needs.pretender((server, helper) => {- server.get("/chat/chat_channels.json", () =>- helper.response({ public_channels: [fabricators.chatChannel()] })- );-- server.get("/chat/:chat_channel_id/messages.json", () =>- helper.response(generateChatView(loggedInUser()))- );- });-- test("Switching off full screen brings you back to previous route", async function (assert) {- this.container.lookup("service:full-page-chat").exit();- await visit("/t/-/280");- await visit("/chat");-- assert.equal(currentURL(), "/chat/channel/1/my-category-title");-- await click(".chat-full-screen-button");-- assert.ok(- currentURL().startsWith("/t/internationalization-localization/280"),- "it redirects back to the visited topic before going full screen"- );- });-});diff --git a/plugins/chat/test/javascripts/acceptance/user-card-chat-test.js b/plugins/chat/test/javascripts/acceptance/user-card-chat-test.jsindex 2387a614ef7..a4750fea4e4 100644--- a/plugins/chat/test/javascripts/acceptance/user-card-chat-test.js+++ b/plugins/chat/test/javascripts/acceptance/user-card-chat-test.js@@ -7,7 +7,7 @@ import {query,visible,} from "discourse/tests/helpers/qunit-helpers";-import { click, settled, visit } from "@ember/test-helpers";+import { click, visit } from "@ember/test-helpers";import {chatChannels,directMessageChannels,@@ -83,17 +83,15 @@ acceptance("Discourse Chat - User card test", function (needs) {test("user card has chat button that opens the correct channel", async function (assert) {this.chatService.set("sidebarActive", false);- this.chatService.set("chatWindowFullPage", false);- await visit("/latest");- this.appEvents.trigger("chat:toggle-open");- await settled();-- await click(".topic-chat-drawer-header__return-to-channels-btn");+ await visit("/");+ await click(".header-dropdown-toggle.open-chat");await click(".chat-channel-row.chat-channel-9");await click("[data-user-card='hawk']");+assert.ok(exists(".user-card-chat-btn"));await click(".user-card-chat-btn");+assert.ok(visible(".topic-chat-float-container"), "chat float is open");assert.ok(query(".topic-chat-container").classList.contains("channel-75"));});diff --git a/plugins/chat/test/javascripts/components/chat-channel-row-test.js b/plugins/chat/test/javascripts/components/chat-channel-row-test.jsindex ae1c968f394..6d3a1b37beb 100644--- a/plugins/chat/test/javascripts/components/chat-channel-row-test.js+++ b/plugins/chat/test/javascripts/components/chat-channel-row-test.js@@ -3,7 +3,6 @@ import componentTest, {} from "discourse/tests/helpers/component-test";import { exists } from "discourse/tests/helpers/qunit-helpers";import hbs from "htmlbars-inline-precompile";-import { click, triggerKeyEvent } from "@ember/test-helpers";import fabricators from "../helpers/fabricators";import { module } from "qunit";@@ -39,42 +38,6 @@ module("Discourse Chat | Component | chat-channel-row", function (hooks) {},});- componentTest("receives click", {- template: hbs`{{chat-channel-row switchChannel=switchChannel channel=channel}}`,-- beforeEach() {- this.set("switchedChannel", null);- this.set("channel", fabricators.chatChannel());- this.set("switchChannel", (channel) =>- this.set("switchedChannel", channel.id)- );- },-- async test(assert) {- await click(".chat-channel-row");-- assert.strictEqual(this.switchedChannel, this.channel.id);- },- });-- componentTest("receives Enter keyup", {- template: hbs`{{chat-channel-row switchChannel=switchChannel channel=channel}}`,-- beforeEach() {- this.set("switchedChannel", null);- this.set("channel", fabricators.chatChannel());- this.set("switchChannel", (channel) =>- this.set("switchedChannel", channel.id)- );- },-- async test(assert) {- await triggerKeyEvent(".chat-channel-row", "keyup", "Enter");-- assert.strictEqual(this.switchedChannel, this.channel.id);- },- });-componentTest("a row is active when the associated channel is active and visible",{diff --git a/plugins/chat/test/javascripts/components/chat-channel-settings-view-test.js b/plugins/chat/test/javascripts/components/chat-channel-settings-view-test.jsindex c869b71f212..73dce053f4f 100644--- a/plugins/chat/test/javascripts/components/chat-channel-settings-view-test.js+++ b/plugins/chat/test/javascripts/components/chat-channel-settings-view-test.js@@ -1,13 +1,11 @@import componentTest, {setupRenderingTest,} from "discourse/tests/helpers/component-test";-import { exists } from "discourse/tests/helpers/qunit-helpers";import hbs from "htmlbars-inline-precompile";import fabricators from "../helpers/fabricators";import selectKit from "discourse/tests/helpers/select-kit-helper";import pretender from "discourse/tests/helpers/create-pretender";import { CHATABLE_TYPES } from "discourse/plugins/chat/discourse/models/chat-channel";-import { set } from "@ember/object";import { module } from "qunit";function membershipFixture(id, options = {}) {@@ -221,50 +219,3 @@ module(});});--module(- "Discourse Chat | Component | chat-channel-settings-view | Public channel - admin user",- function (hooks) {- setupRenderingTest(hooks);-- componentTest("admin actions", {- template: hbs`{{chat-channel-settings-view channel=channel}}`,-- beforeEach() {- set(this.currentUser, "admin", true);- set(this.currentUser, "has_chat_enabled", true);- this.siteSettings.chat_enabled = true;-- this.set("channel", fabricators.chatChannel());- },-- async test(assert) {- assert.ok(exists(".close-btn"));- assert.ok(exists(".delete-btn"));- },- });- }-);--module(- "Discourse Chat | Component | chat-channel-settings-view | Archived Public channel - admin user",- function (hooks) {- setupRenderingTest(hooks);-- componentTest("archive action", {- template: hbs`{{chat-channel-settings-view channel=channel}}`,-- beforeEach() {- set(this.currentUser, "admin", true);- set(this.currentUser, "has_chat_enabled", true);- this.siteSettings.chat_enabled = true;- this.siteSettings.chat_allow_archiving_channels = true;- this.set("channel", fabricators.chatChannel());- },-- async test(assert) {- assert.ok(exists(".archive-btn"));- },- });- }-);diff --git a/plugins/chat/test/javascripts/components/chat-message-test.js b/plugins/chat/test/javascripts/components/chat-message-test.jsindex ec688ab127c..a937d668283 100644--- a/plugins/chat/test/javascripts/components/chat-message-test.js+++ b/plugins/chat/test/javascripts/components/chat-message-test.js@@ -55,7 +55,6 @@ module("Discourse Chat | Component | chat-message", function (hooks) {onStartSelectingMessages: () => {},onSelectMessage: () => {},bulkSelectMessages: () => {},- fullPage: false,afterReactionAdded: () => {},onHoverMessage: () => {},};@@ -73,7 +72,6 @@ module("Discourse Chat | Component | chat-message", function (hooks) {onStartSelectingMessages=onStartSelectingMessagesonSelectMessage=onSelectMessagebulkSelectMessages=bulkSelectMessages- fullPage=fullPageonHoverMessage=onHoverMessageafterReactionAdded=reStickScrollIfNeeded}}`;diff --git a/plugins/chat/test/javascripts/unit/services/chat-preferred-mode-test.js b/plugins/chat/test/javascripts/unit/services/chat-preferred-mode-test.jsdeleted file mode 100644index 7736fc30519..00000000000--- a/plugins/chat/test/javascripts/unit/services/chat-preferred-mode-test.js+++ /dev/null@@ -1,38 +0,0 @@-import { module, test } from "qunit";-import { getOwner } from "discourse-common/lib/get-owner";-import Site from "discourse/models/site";--module(- "Discourse Chat | Unit | Service | chat-preferred-mode",- function (hooks) {- hooks.beforeEach(function () {- Site.currentProp("mobileView", false);-- this.chatPreferredMode = getOwner(this).lookup(- "service:chat-preferred-mode"- );- });-- test("defaults", function (assert) {- assert.strictEqual(this.chatPreferredMode.isDrawer, true);- assert.strictEqual(this.chatPreferredMode.isFullPage, false);-- Site.currentProp("mobileView", true);-- assert.strictEqual(this.chatPreferredMode.isDrawer, false);- assert.strictEqual(this.chatPreferredMode.isFullPage, true);- });-- test("setFullPage", function (assert) {- this.chatPreferredMode.setFullPage();- assert.strictEqual(this.chatPreferredMode.isFullPage, true);- assert.strictEqual(this.chatPreferredMode.isDrawer, false);- });-- test("setDrawer", function (assert) {- this.chatPreferredMode.setDrawer();- assert.strictEqual(this.chatPreferredMode.isFullPage, false);- assert.strictEqual(this.chatPreferredMode.isDrawer, true);- });- }-);diff --git a/plugins/chat/test/javascripts/unit/services/chat-state-manager-test.js b/plugins/chat/test/javascripts/unit/services/chat-state-manager-test.jsnew file mode 100644index 00000000000..596d8dd5a21--- /dev/null+++ b/plugins/chat/test/javascripts/unit/services/chat-state-manager-test.js@@ -0,0 +1,82 @@+import { module, test } from "qunit";+import { setupTest } from "ember-qunit";+import Site from "discourse/models/site";+import sinon from "sinon";++module(+ "Discourse Chat | Unit | Service | chat-state-manager",+ function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ this.subject = this.owner.lookup("service:chat-state-manager");+ });++ hooks.afterEach(function () {+ this.subject.reset();+ });++ test("isFullPagePreferred", function (assert) {+ assert.notOk(this.subject.isFullPagePreferred);++ this.subject.prefersFullPage();++ assert.ok(this.subject.isFullPagePreferred);++ this.subject.prefersDrawer();++ assert.notOk(this.subject.isFullPagePreferred);++ this.subject.prefersDrawer();+ Site.currentProp("mobileView", true);++ assert.ok(this.subject.isFullPagePreferred);+ });++ test("isDrawerPreferred", function (assert) {+ assert.ok(this.subject.isDrawerPreferred);++ this.subject.prefersFullPage();++ assert.notOk(this.subject.isDrawerPreferred);++ this.subject.prefersDrawer();++ assert.ok(this.subject.isDrawerPreferred);+ });++ test("lastKnownChatURL", function (assert) {+ assert.strictEqual(this.subject.lastKnownChatURL, "/chat");++ sinon.stub(this.subject.router, "currentURL").value("/foo");+ this.subject.storeChatURL();++ assert.strictEqual(this.subject.lastKnownChatURL, "/foo");++ this.subject.storeChatURL("/bar");++ assert.strictEqual(this.subject.lastKnownChatURL, "/bar");+ });++ test("lastKnownAppURL", function (assert) {+ assert.strictEqual(this.subject.lastKnownAppURL, "/latest");++ sinon.stub(this.subject.router, "currentURL").value("/foo");+ this.subject.storeAppURL();++ assert.strictEqual(this.subject.lastKnownAppURL, "/foo");++ this.subject.storeAppURL("/bar");++ assert.strictEqual(this.subject.lastKnownAppURL, "/bar");+ });++ test("isFullPage", function (assert) {+ sinon.stub(this.subject.router, "currentRouteName").value("foo");+ assert.notOk(this.subject.isFullPage);++ sinon.stub(this.subject.router, "currentRouteName").value("chat");+ assert.ok(this.subject.isFullPage);+ });+ }+);diff --git a/plugins/chat/test/javascripts/unit/services/full-page-chat-test.js b/plugins/chat/test/javascripts/unit/services/full-page-chat-test.jsdeleted file mode 100644index a893799cd23..00000000000--- a/plugins/chat/test/javascripts/unit/services/full-page-chat-test.js+++ /dev/null@@ -1,40 +0,0 @@-import { module, test } from "qunit";-import { setupTest } from "ember-qunit";--module("Discourse Chat | Unit | Service | full-page-chat", function (hooks) {- setupTest(hooks);-- hooks.beforeEach(function () {- this.fullPageChat = this.owner.lookup("service:full-page-chat");- });-- hooks.afterEach(function () {- this.fullPageChat.exit();- });-- test("defaults", function (assert) {- assert.strictEqual(this.fullPageChat.isActive, false);- });-- test("enter", function (assert) {- this.fullPageChat.enter();- assert.strictEqual(this.fullPageChat.isActive, true);- });-- test("exit", function (assert) {- this.fullPageChat.enter();- assert.strictEqual(this.fullPageChat.isActive, true);- this.fullPageChat.exit();- assert.strictEqual(this.fullPageChat.isActive, false);- });-- test("previous route", function (assert) {- const name = "foo";- const params = { id: 1, slug: "bar" };- this.fullPageChat.enter({ name, params });- const routeInfo = this.fullPageChat.exit();-- assert.strictEqual(routeInfo.name, name);- assert.deepEqual(routeInfo.params, params);- });-});