FIX: Remove chat default channel setting (#28170)

* FIX: Remove chat default channel being applied to mobile chat and drawer

* DEV: removing chat_default_channel_id setting

* DEV: add migration to remove chat default channel id

* DEV: remove default_channel_validator and tests
This commit is contained in:
Gabriel Grubba 2024-07-31 14:12:10 -03:00 committed by GitHub
parent 30048ab97f
commit 633a19fcc0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 11 additions and 74 deletions

View File

@ -0,0 +1,10 @@
# frozen_string_literal: true
class RemoveChatDefaultChannelId < ActiveRecord::Migration[7.1]
def up
execute "DELETE FROM site_settings WHERE name = 'chat_default_channel_id'"
end
def down
raise ActiveRecord::IrreversibleMigration
end
end

View File

@ -1,17 +0,0 @@
# frozen_string_literal: true
module Chat
class DefaultChannelValidator
def initialize(opts = {})
@opts = opts
end
def valid_value?(value)
!!(value == "" || Chat::Channel.find_by(id: value.to_i)&.public_channel?)
end
def error_message
I18n.t("site_settings.errors.chat_default_channel")
end
end
end

View File

@ -12,30 +12,13 @@ export default class ChatChannelsRoute extends DiscourseRoute {
beforeModel() {
const id = this.currentUser.custom_fields.last_chat_channel_id;
const defaultChannelId = this.siteSettings.chat_default_channel_id;
if (this.site.desktopView) {
if (id) {
this.chatChannelsManager.find(id).then((c) => {
return this.router.replaceWith("chat.channel", ...c.routeModels);
});
} else {
// first time browsing chat in desktop and the preferred index is channels
if (defaultChannelId) {
this.chatChannelsManager.find(defaultChannelId).then((c) => {
return this.router.replaceWith("chat.channel", ...c.routeModels);
});
} else {
this.router.replaceWith("chat.browse.open");
}
}
} else {
if (
defaultChannelId &&
this.router.currentRoute?.parent?.params?.channelId !== defaultChannelId
) {
this.chatChannelsManager.find(defaultChannelId).then((c) => {
return this.router.replaceWith("chat.channel", ...c.routeModels);
});
this.router.replaceWith("chat.browse.open");
}
}
}

View File

@ -179,14 +179,6 @@ export default class ChatDrawerRouter extends Service {
return this.stateFor(this.#routeFromURL("/chat/direct-messages"));
}
if (this.siteSettings.chat_default_channel_id) {
return this.chatChannelsManager
.find(this.siteSettings.chat_default_channel_id)
.then((c) => {
return this.router.replaceWith("chat.channel", ...c.routeModels);
});
}
if (!this.siteSettings.enable_public_channels) {
return this.stateFor(this.#routeFromURL("/chat/direct-messages"));
}

View File

@ -11,7 +11,6 @@ en:
chat_allowed_messages_for_other_trust_levels: "Number of messages that users with trust levels 1-4 is allowed to send in 30 seconds. Set to '0' to disable limit."
chat_silence_user_sensitivity: "The likelihood that a user flagged in chat will be automatically silenced."
chat_auto_silence_from_flags_duration: "Number of minutes that users will be silenced for when they are automatically silenced due to flagged chat messages."
chat_default_channel_id: "The chat channel that will be opened by default when a user has no unread messages or mentions in other channels."
chat_duplicate_message_sensitivity: "The likelihood that a duplicate message by the same sender will be blocked in a short period. Decimal number between 0 and 1.0, with 1.0 being the highest setting (blocks messages more frequently in a shorter amount of time). Set to `0` to allow duplicate messages."
chat_minimum_message_length: "Minimum number of characters for a chat message."
chat_allow_uploads: "Allow uploads in public chat channels and direct message channels."

View File

@ -63,10 +63,6 @@ chat:
- archived
- open
- closed
chat_default_channel_id:
default: ""
client: true
validator: "Chat::DefaultChannelValidator"
chat_duplicate_message_sensitivity:
type: float
default: 0.5

View File

@ -1,26 +0,0 @@
# frozen_string_literal: true
describe Chat::DefaultChannelValidator do
fab!(:channel) { Fabricate(:category_channel) }
it "provides an error message" do
validator = described_class.new
expect(validator.error_message).to eq(I18n.t("site_settings.errors.chat_default_channel"))
end
it "returns true if public channel id" do
validator = described_class.new
expect(validator.valid_value?(channel.id)).to eq(true)
end
it "returns true if empty string" do
validator = described_class.new
expect(validator.valid_value?("")).to eq(true)
end
it "returns false if not a public channel" do
validator = described_class.new
channel.destroy!
expect(validator.valid_value?(channel.id)).to eq(false)
end
end