mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 04:14:38 +08:00
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:
@ -5,6 +5,21 @@ export default class ChatIndexRoute extends DiscourseRoute {
|
|||||||
@service chat;
|
@service chat;
|
||||||
@service chatChannelsManager;
|
@service chatChannelsManager;
|
||||||
@service router;
|
@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() {
|
activate() {
|
||||||
this.chat.activeChannel = null;
|
this.chat.activeChannel = null;
|
||||||
@ -13,8 +28,20 @@ export default class ChatIndexRoute extends DiscourseRoute {
|
|||||||
redirect() {
|
redirect() {
|
||||||
// on mobile redirect user to the first footer tab route
|
// on mobile redirect user to the first footer tab route
|
||||||
if (this.site.mobileView) {
|
if (this.site.mobileView) {
|
||||||
|
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");
|
return this.router.replaceWith("chat.channels");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// We are on desktop. Check for a channel to enter and transition if so
|
// We are on desktop. Check for a channel to enter and transition if so
|
||||||
const id = this.chat.getIdealFirstChannelId();
|
const id = this.chat.getIdealFirstChannelId();
|
||||||
|
@ -25,6 +25,7 @@ en:
|
|||||||
chat_editing_grace_period: "For (n) seconds after sending a chat, editing will not display the (edited) tag by the chat message."
|
chat_editing_grace_period: "For (n) seconds after sending a chat, editing will not display the (edited) tag by the chat message."
|
||||||
chat_editing_grace_period_max_diff_low_trust: "Maximum number of character changes allowed in chat editing grace period, if more changed display the (edited) tag by the chat message (trust level 0 and 1)."
|
chat_editing_grace_period_max_diff_low_trust: "Maximum number of character changes allowed in chat editing grace period, if more changed display the (edited) tag by the chat message (trust level 0 and 1)."
|
||||||
chat_editing_grace_period_max_diff_high_trust: "Maximum number of character changes allowed in chat editing grace period, if more changed display the (edited) tag by the chat message (trust level 2 and up)."
|
chat_editing_grace_period_max_diff_high_trust: "Maximum number of character changes allowed in chat editing grace period, if more changed display the (edited) tag by the chat message (trust level 2 and up)."
|
||||||
|
chat_preferred_mobile_index: "Preferred tab when loading /chat on mobile."
|
||||||
errors:
|
errors:
|
||||||
chat_default_channel: "The default chat channel must be a public channel."
|
chat_default_channel: "The default chat channel must be a public channel."
|
||||||
direct_message_enabled_groups_invalid: "You must specify at least one group for this setting. If you do not want anyone except staff to send direct messages, choose the staff group."
|
direct_message_enabled_groups_invalid: "You must specify at least one group for this setting. If you do not want anyone except staff to send direct messages, choose the staff group."
|
||||||
|
@ -137,3 +137,11 @@ chat:
|
|||||||
type: integer
|
type: integer
|
||||||
default: 40
|
default: 40
|
||||||
min: 0
|
min: 0
|
||||||
|
chat_preferred_mobile_index:
|
||||||
|
client: true
|
||||||
|
type: enum
|
||||||
|
default: channels
|
||||||
|
choices:
|
||||||
|
- channels
|
||||||
|
- direct_messages
|
||||||
|
- my_threads
|
||||||
|
@ -201,6 +201,60 @@ RSpec.describe "List channels | mobile", type: :system, mobile: true do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when chat_preferred_mobile_index is set to direct_messages" do
|
||||||
|
before { SiteSetting.chat_preferred_mobile_index = "direct_messages" }
|
||||||
|
|
||||||
|
it "changes the default index" do
|
||||||
|
visit("/chat")
|
||||||
|
|
||||||
|
expect(page).to have_current_path("/chat/direct-messages")
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when user can't use direct messages" do
|
||||||
|
before { SiteSetting.direct_message_enabled_groups = Group::AUTO_GROUPS[:staff] }
|
||||||
|
|
||||||
|
it "redirects to channels" do
|
||||||
|
visit("/chat")
|
||||||
|
|
||||||
|
expect(page).to have_current_path("/chat/channels")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when chat_preferred_mobile_index is not set" do
|
||||||
|
it "redirects to channels" do
|
||||||
|
visit("/chat")
|
||||||
|
|
||||||
|
expect(page).to have_current_path("/chat/channels")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when chat_preferred_mobile_index is set to my_threads" do
|
||||||
|
before do
|
||||||
|
SiteSetting.chat_threads_enabled = true
|
||||||
|
SiteSetting.chat_preferred_mobile_index = "my_threads"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "redirects to threads" do
|
||||||
|
channel = Fabricate(:chat_channel, threading_enabled: true)
|
||||||
|
channel.add(current_user)
|
||||||
|
|
||||||
|
visit("/chat")
|
||||||
|
|
||||||
|
expect(page).to have_current_path("/chat/threads")
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when no threads" do
|
||||||
|
before { SiteSetting.chat_threads_enabled = false }
|
||||||
|
|
||||||
|
it "redirects to channels" do
|
||||||
|
visit("/chat")
|
||||||
|
|
||||||
|
expect(page).to have_current_path("/chat/channels")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "has a new dm channel button" do
|
it "has a new dm channel button" do
|
||||||
visit("/chat/direct-messages")
|
visit("/chat/direct-messages")
|
||||||
find(".c-navbar__new-dm-button").click
|
find(".c-navbar__new-dm-button").click
|
||||||
|
Reference in New Issue
Block a user