From 616885895a43bbffeff476fd211d0c8f8fc93bfe Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Wed, 10 May 2023 18:46:06 +0200 Subject: [PATCH] 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. cc2570fce38579202d0e295c153310310f6feb14) We don't actually _need_ to extend the core class, we can just make our own for chat, let's do this instead. --- .../app/models/chat/user_chat_thread_membership.rb | 2 +- plugins/chat/lib/chat/notification_levels.rb | 9 +++++++++ .../chat/lib/chat/notification_levels_extension.rb | 13 ------------- plugins/chat/plugin.rb | 1 - 4 files changed, 10 insertions(+), 15 deletions(-) create mode 100644 plugins/chat/lib/chat/notification_levels.rb delete mode 100644 plugins/chat/lib/chat/notification_levels_extension.rb diff --git a/plugins/chat/app/models/chat/user_chat_thread_membership.rb b/plugins/chat/app/models/chat/user_chat_thread_membership.rb index b906211bb23..0b2793e51c2 100644 --- a/plugins/chat/app/models/chat/user_chat_thread_membership.rb +++ b/plugins/chat/app/models/chat/user_chat_thread_membership.rb @@ -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 diff --git a/plugins/chat/lib/chat/notification_levels.rb b/plugins/chat/lib/chat/notification_levels.rb new file mode 100644 index 00000000000..3ac06d6a0fa --- /dev/null +++ b/plugins/chat/lib/chat/notification_levels.rb @@ -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 diff --git a/plugins/chat/lib/chat/notification_levels_extension.rb b/plugins/chat/lib/chat/notification_levels_extension.rb deleted file mode 100644 index d57a65218e7..00000000000 --- a/plugins/chat/lib/chat/notification_levels_extension.rb +++ /dev/null @@ -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 diff --git a/plugins/chat/plugin.rb b/plugins/chat/plugin.rb index 81e1ad040d8..d041adfeb3b 100644 --- a/plugins/chat/plugin.rb +++ b/plugins/chat/plugin.rb @@ -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)