module RedmineEventOutbox
  module Patches
    module JournalMessagePatch
      def self.included(base)
        base.class_eval do
          # Local fork hook: JournalMessage is the per-email metadata layer for
          # helpdesk conversations, so indexers should react to it directly.
          after_commit :record_event_outbox_journal_message_created, :on => :create
          after_commit :record_event_outbox_journal_message_updated, :on => :update
        end
      end

      def record_event_outbox_journal_message_created
        RedmineEventOutbox::Event.record_journal_message_created(self, User.current)
      end

      def record_event_outbox_journal_message_updated
        RedmineEventOutbox::Event.record_journal_message_updated(self, User.current)
      end
    end
  end
end
