Class: SpreeCmCommissioner::CustomerNotificationSender
- Inherits:
-
BaseInteractor
- Object
- BaseInteractor
- SpreeCmCommissioner::CustomerNotificationSender
- Defined in:
- app/interactors/spree_cm_commissioner/customer_notification_sender.rb
Instance Method Summary collapse
- #call ⇒ Object
- #deliver_notification_to_user(user) ⇒ Object
- #end_users ⇒ Object
- #send_notification ⇒ Object
- #send_to_specific_users(user_ids) ⇒ Object
- #send_to_target_users ⇒ Object
-
#update_sent_at ⇒ Object
even sent_at is present, it still can be sent but will only to users that not yet received the notification.
- #users_not_received_notifications ⇒ Object
Instance Method Details
#call ⇒ Object
5 6 7 8 |
# File 'app/interactors/spree_cm_commissioner/customer_notification_sender.rb', line 5 def call send_notification update_sent_at end |
#deliver_notification_to_user(user) ⇒ Object
38 39 40 41 42 43 |
# File 'app/interactors/spree_cm_commissioner/customer_notification_sender.rb', line 38 def deliver_notification_to_user(user) SpreeCmCommissioner::CustomerContentNotificationCreator.call( user_id: user.id, customer_notification_id: customer_notification.id ) end |
#end_users ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/interactors/spree_cm_commissioner/customer_notification_sender.rb', line 57 def end_users if customer_notification.notification_taxons.exists? taxon_ids = customer_notification.notification_taxons.pluck(:taxon_id) SpreeCmCommissioner::UsersByEventFetcherQuery .new(taxon_ids) .call .end_users_push_notificable else Spree.user_class.end_users_push_notificable end end |
#send_notification ⇒ Object
17 18 19 20 21 22 23 |
# File 'app/interactors/spree_cm_commissioner/customer_notification_sender.rb', line 17 def send_notification if user_ids.present? send_to_specific_users(user_ids) else send_to_target_users end end |
#send_to_specific_users(user_ids) ⇒ Object
25 26 27 28 29 30 |
# File 'app/interactors/spree_cm_commissioner/customer_notification_sender.rb', line 25 def send_to_specific_users(user_ids) users = Spree::User.push_notificable.where(id: user_ids) users.find_each do |user| deliver_notification_to_user(user) end end |
#send_to_target_users ⇒ Object
32 33 34 35 36 |
# File 'app/interactors/spree_cm_commissioner/customer_notification_sender.rb', line 32 def send_to_target_users users_not_received_notifications.find_each do |user| deliver_notification_to_user(user) end end |
#update_sent_at ⇒ Object
even sent_at is present, it still can be sent but will only to users that not yet received the notification
12 13 14 15 |
# File 'app/interactors/spree_cm_commissioner/customer_notification_sender.rb', line 12 def update_sent_at customer_notification.sent_at = Time.current customer_notification.save end |
#users_not_received_notifications ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/interactors/spree_cm_commissioner/customer_notification_sender.rb', line 45 def users_not_received_notifications end_users .joins( "LEFT JOIN cm_notifications ON ( cm_notifications.recipient_id = spree_users.id AND cm_notifications.notificable_type = 'SpreeCmCommissioner::CustomerNotification' AND cm_notifications.notificable_id = #{customer_notification.id} )" ) .where(cm_notifications: { id: nil }) end |