FEATURE: introduces chat_preferred_mobile_index setting (#25927)

`chat_preferred_mobile_index` allows to set the preferred default tab when loading chat on mobile.

Current choices are:
- channels
- direct_messages
- my_threads
This commit is contained in:
Joffrey JAFFEUX
2024-02-28 12:05:05 +01:00
committed by GitHub
parent 4116bd9595
commit 0e17ff8d09
4 changed files with 91 additions and 1 deletions

View File

@ -5,6 +5,21 @@ export default class ChatIndexRoute extends DiscourseRoute {
@service chat;
@service chatChannelsManager;
@service router;
@service siteSettings;
@service currentUser;
get hasThreads() {
if (!this.siteSettings.chat_threads_enabled) {
return false;
}
return this.currentUser?.chat_channels?.public_channels?.some(
(channel) => channel.threading_enabled
);
}
get hasDirectMessages() {
return this.chat.userCanAccessDirectMessages;
}
activate() {
this.chat.activeChannel = null;
@ -13,7 +28,19 @@ export default class ChatIndexRoute extends DiscourseRoute {
redirect() {
// on mobile redirect user to the first footer tab route
if (this.site.mobileView) {
return this.router.replaceWith("chat.channels");
if (
this.siteSettings.chat_preferred_mobile_index === "my_threads" &&
this.hasThreads
) {
return this.router.replaceWith("chat.threads");
} else if (
this.siteSettings.chat_preferred_mobile_index === "direct_messages" &&
this.hasDirectMessages
) {
return this.router.replaceWith("chat.direct-messages");
} else {
return this.router.replaceWith("chat.channels");
}
}
// We are on desktop. Check for a channel to enter and transition if so