mirror of
https://github.com/discourse/discourse.git
synced 2025-02-12 22:34:57 +00:00
Currently it’s not possible to delete a category if an associated chat channel is present even if there are no messages in this channel. This can lead to annoying situations for our users. This patch addresses the issue by checking if the channel is empty instead of just checking if there is a channel.
20 lines
414 B
Ruby
20 lines
414 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Chat::CategoryExtension
|
|
extend ActiveSupport::Concern
|
|
|
|
include Chatable
|
|
|
|
prepended { has_one :category_channel, as: :chatable }
|
|
|
|
def cannot_delete_reason
|
|
return I18n.t("category.cannot_delete.has_chat_channels") if category_channel
|
|
super
|
|
end
|
|
|
|
def deletable_for_chat?
|
|
return true if !category_channel
|
|
category_channel.chat_messages_empty?
|
|
end
|
|
end
|