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.

70 lines
2.1 KiB

  1. # frozen_string_literal: true
  2. class NotificationMailer < ApplicationMailer
  3. helper StreamEntriesHelper
  4. def mention(recipient, notification)
  5. @me = recipient
  6. @status = notification.target_status
  7. locale_for_account(@me) do
  8. mail to: @me.user.email, subject: I18n.t('notification_mailer.mention.subject', name: @status.account.acct)
  9. end
  10. end
  11. def follow(recipient, notification)
  12. @me = recipient
  13. @account = notification.from_account
  14. locale_for_account(@me) do
  15. mail to: @me.user.email, subject: I18n.t('notification_mailer.follow.subject', name: @account.acct)
  16. end
  17. end
  18. def favourite(recipient, notification)
  19. @me = recipient
  20. @account = notification.from_account
  21. @status = notification.target_status
  22. locale_for_account(@me) do
  23. mail to: @me.user.email, subject: I18n.t('notification_mailer.favourite.subject', name: @account.acct)
  24. end
  25. end
  26. def reblog(recipient, notification)
  27. @me = recipient
  28. @account = notification.from_account
  29. @status = notification.target_status
  30. locale_for_account(@me) do
  31. mail to: @me.user.email, subject: I18n.t('notification_mailer.reblog.subject', name: @account.acct)
  32. end
  33. end
  34. def follow_request(recipient, notification)
  35. @me = recipient
  36. @account = notification.from_account
  37. locale_for_account(@me) do
  38. mail to: @me.user.email, subject: I18n.t('notification_mailer.follow_request.subject', name: @account.acct)
  39. end
  40. end
  41. def digest(recipient, opts = {})
  42. @me = recipient
  43. @since = opts[:since] || @me.user.last_emailed_at || @me.user.current_sign_in_at
  44. @notifications = Notification.where(account: @me, activity_type: 'Mention').where('created_at > ?', @since)
  45. @follows_since = Notification.where(account: @me, activity_type: 'Follow').where('created_at > ?', @since).count
  46. return if @notifications.empty?
  47. locale_for_account(@me) do
  48. mail to: @me.user.email,
  49. subject: I18n.t(
  50. :subject,
  51. scope: [:notification_mailer, :digest],
  52. count: @notifications.size
  53. )
  54. end
  55. end
  56. end