triggers_subscriptions.rb 953 B

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # Trigger GraphQL subscriptions on ticket changes.
  3. module Ticket::TriggersSubscriptions
  4. extend ActiveSupport::Concern
  5. included do
  6. after_update_commit :trigger_subscriptions
  7. after_update_commit :trigger_checklist_subscriptions
  8. end
  9. private
  10. def trigger_subscriptions
  11. Gql::Subscriptions::TicketUpdates.trigger(self, arguments: { ticket_id: Gql::ZammadSchema.id_from_object(self) })
  12. end
  13. def trigger_checklist_subscriptions
  14. return if checklist_items.none?
  15. return if %i[title state_id].none? { |attr| saved_change_to_attribute?(attr) }
  16. checklists = checklist_items.compact.map(&:checklist).uniq
  17. checklists.each do |checklist|
  18. Gql::Subscriptions::Ticket::ChecklistUpdates.trigger(
  19. checklist,
  20. arguments: {
  21. ticket_id: Gql::ZammadSchema.id_from_object(checklist.ticket),
  22. }
  23. )
  24. end
  25. end
  26. end