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.

65 lines
2.2 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. I18n.with_locale(@me.user.locale || I18n.default_locale) 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. I18n.with_locale(@me.user.locale || I18n.default_locale) 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. I18n.with_locale(@me.user.locale || I18n.default_locale) 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. I18n.with_locale(@me.user.locale || I18n.default_locale) 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. I18n.with_locale(@me.user.locale || I18n.default_locale) 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. I18n.with_locale(@me.user.locale || I18n.default_locale) do
  48. mail to: @me.user.email, subject: I18n.t('notification_mailer.digest.subject', count: @notifications.size)
  49. end
  50. end
  51. end