triggers_subscriptions.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # Trigger GraphQL subscriptions on ticket changes.
  3. module Taskbar::TriggersSubscriptions
  4. extend ActiveSupport::Concern
  5. included do
  6. attr_accessor :skip_live_user_trigger, :skip_item_trigger
  7. after_commit :trigger_live_user_subscriptions, unless: :skip_live_user_trigger
  8. after_create_commit :trigger_taskbar_item_create_subscriptions, unless: :skip_item_trigger
  9. after_update_commit :trigger_taskbar_item_update_subscriptions, unless: :skip_item_trigger
  10. after_destroy_commit :trigger_taskbar_item_destroy_subscriptions, unless: :skip_item_trigger
  11. after_update_commit :trigger_taskbar_item_state_update_subscriptions
  12. end
  13. private
  14. def trigger_live_user_subscriptions
  15. return true if !saved_change_to_attribute?('preferences')
  16. return true if !persisted?
  17. Gql::Subscriptions::TicketLiveUserUpdates.trigger(
  18. self,
  19. arguments: {
  20. user_id: Gql::ZammadSchema.id_from_internal_id('User', user_id),
  21. key: key,
  22. app: app,
  23. }
  24. )
  25. end
  26. def trigger_taskbar_item_create_subscriptions
  27. Gql::Subscriptions::User::Current::TaskbarItemUpdates.trigger_after_create(self)
  28. end
  29. def trigger_taskbar_item_update_subscriptions
  30. # See specific subscription for prio changes / list sorting.
  31. return true if saved_change_to_attribute?('prio')
  32. Gql::Subscriptions::User::Current::TaskbarItemUpdates.trigger_after_update(self)
  33. end
  34. def trigger_taskbar_item_destroy_subscriptions
  35. Gql::Subscriptions::User::Current::TaskbarItemUpdates.trigger_after_destroy(self)
  36. end
  37. def trigger_taskbar_item_state_update_subscriptions
  38. return true if !saved_change_to_attribute?('state')
  39. return true if !app.eql?('desktop')
  40. return true if destroyed?
  41. Gql::Subscriptions::User::Current::TaskbarItemStateUpdates.trigger(
  42. nil,
  43. arguments: {
  44. taskbar_item_id: Gql::ZammadSchema.id_from_internal_id('Taskbar', id),
  45. }
  46. )
  47. end
  48. end