The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

56 lines
1.3 KiB

  1. # frozen_string_literal: true
  2. class NotifyService < BaseService
  3. def call(recipient, activity)
  4. @recipient = recipient
  5. @activity = activity
  6. @notification = Notification.new(account: @recipient, activity: @activity)
  7. return if blocked?
  8. create_notification
  9. send_email if email_enabled?
  10. rescue ActiveRecord::RecordInvalid
  11. return
  12. end
  13. private
  14. def blocked_mention?
  15. FeedManager.instance.filter?(:mentions, @notification.mention.status, @recipient)
  16. end
  17. def blocked_favourite?
  18. false
  19. end
  20. def blocked_follow?
  21. false
  22. end
  23. def blocked_reblog?
  24. false
  25. end
  26. def blocked?
  27. blocked = false
  28. blocked ||= @recipient.id == @notification.from_account.id
  29. blocked ||= @recipient.blocking?(@notification.from_account)
  30. blocked ||= send("blocked_#{@notification.type}?")
  31. blocked
  32. end
  33. def create_notification
  34. @notification.save!
  35. FeedManager.instance.broadcast(@recipient.id, type: 'notification', message: FeedManager.instance.inline_render(@recipient, 'api/v1/notifications/show', @notification))
  36. end
  37. def send_email
  38. NotificationMailer.send(@notification.type, @recipient, @notification).deliver_later
  39. end
  40. def email_enabled?
  41. @recipient.user.settings(:notification_emails).send(@notification.type)
  42. end
  43. end