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.

88 lines
2.7 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. return if @me.user.disabled?
  8. locale_for_account(@me) do
  9. thread_by_conversation(@status.conversation)
  10. mail to: @me.user.email, subject: I18n.t('notification_mailer.mention.subject', name: @status.account.acct)
  11. end
  12. end
  13. def follow(recipient, notification)
  14. @me = recipient
  15. @account = notification.from_account
  16. return if @me.user.disabled?
  17. locale_for_account(@me) do
  18. mail to: @me.user.email, subject: I18n.t('notification_mailer.follow.subject', name: @account.acct)
  19. end
  20. end
  21. def favourite(recipient, notification)
  22. @me = recipient
  23. @account = notification.from_account
  24. @status = notification.target_status
  25. return if @me.user.disabled?
  26. locale_for_account(@me) do
  27. thread_by_conversation(@status.conversation)
  28. mail to: @me.user.email, subject: I18n.t('notification_mailer.favourite.subject', name: @account.acct)
  29. end
  30. end
  31. def reblog(recipient, notification)
  32. @me = recipient
  33. @account = notification.from_account
  34. @status = notification.target_status
  35. return if @me.user.disabled?
  36. locale_for_account(@me) do
  37. thread_by_conversation(@status.conversation)
  38. mail to: @me.user.email, subject: I18n.t('notification_mailer.reblog.subject', name: @account.acct)
  39. end
  40. end
  41. def follow_request(recipient, notification)
  42. @me = recipient
  43. @account = notification.from_account
  44. return if @me.user.disabled?
  45. locale_for_account(@me) do
  46. mail to: @me.user.email, subject: I18n.t('notification_mailer.follow_request.subject', name: @account.acct)
  47. end
  48. end
  49. def digest(recipient, **opts)
  50. @me = recipient
  51. @since = opts[:since] || @me.user.last_emailed_at || @me.user.current_sign_in_at
  52. @notifications = Notification.where(account: @me, activity_type: 'Mention').where('created_at > ?', @since)
  53. @follows_since = Notification.where(account: @me, activity_type: 'Follow').where('created_at > ?', @since).count
  54. return if @me.user.disabled? || @notifications.empty?
  55. locale_for_account(@me) do
  56. mail to: @me.user.email,
  57. subject: I18n.t(:subject, scope: [:notification_mailer, :digest], count: @notifications.size)
  58. end
  59. end
  60. private
  61. def thread_by_conversation(conversation)
  62. return if conversation.nil?
  63. msg_id = "<conversation-#{conversation.id}.#{conversation.created_at.strftime('%Y-%m-%d')}@#{Rails.configuration.x.local_domain}>"
  64. headers['In-Reply-To'] = msg_id
  65. headers['References'] = msg_id
  66. end
  67. end