FIX: Chat NotificationLevels extension breaking in prod (#21484)

When setting DISCOURSE_ZEITWERK_EAGER_LOAD=1 to enable
eager loading the previous solution to adding chat_levels
to the core NotificationLevels would break with a module
loading error (c.f. cc2570fce3)

We don't actually _need_ to extend the core class, we can just
make our own for chat, let's do this instead.
This commit is contained in:
Martin Brennan 2023-05-10 18:46:06 +02:00 committed by GitHub
parent 79812db7d3
commit 616885895a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 15 deletions

View File

@ -8,7 +8,7 @@ module Chat
belongs_to :last_read_message, class_name: "Chat::Message", optional: true
belongs_to :thread, class_name: "Chat::Thread", foreign_key: :thread_id
enum :notification_level, NotificationLevels.chat_levels
enum :notification_level, Chat::NotificationLevels.all
end
end

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
module Chat
class NotificationLevels
def self.all
@all_levels ||= Enum.new(muted: 0, normal: 1, tracking: 2, watching: 3)
end
end
end

View File

@ -1,13 +0,0 @@
# frozen_string_literal: true
module Chat
module NotificationLevelsExtension
extend ActiveSupport::Concern
class_methods do
def chat_levels
@chat_levels ||= Enum.new(muted: 0, normal: 1, tracking: 2, watching: 3)
end
end
end
end

View File

@ -63,7 +63,6 @@ after_initialize do
User.prepend Chat::UserExtension
Jobs::UserEmail.prepend Chat::UserEmailExtension
Plugin::Instance.prepend Chat::PluginInstanceExtension
NotificationLevels.prepend Chat::NotificationLevelsExtension
end
if Oneboxer.respond_to?(:register_local_handler)