notification_mailer.rb 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # frozen_string_literal: true
  2. class NotificationMailer < ApplicationMailer
  3. helper :accounts
  4. helper :statuses
  5. helper RoutingHelper
  6. def mention(recipient, notification)
  7. @me = recipient
  8. @status = notification.target_status
  9. return unless @me.user.functional? && @status.present?
  10. locale_for_account(@me) do
  11. thread_by_conversation(@status.conversation)
  12. mail to: @me.user.email, subject: I18n.t('notification_mailer.mention.subject', name: @status.account.acct)
  13. end
  14. end
  15. def follow(recipient, notification)
  16. @me = recipient
  17. @account = notification.from_account
  18. return unless @me.user.functional?
  19. locale_for_account(@me) do
  20. mail to: @me.user.email, subject: I18n.t('notification_mailer.follow.subject', name: @account.acct)
  21. end
  22. end
  23. def favourite(recipient, notification)
  24. @me = recipient
  25. @account = notification.from_account
  26. @status = notification.target_status
  27. return unless @me.user.functional? && @status.present?
  28. locale_for_account(@me) do
  29. thread_by_conversation(@status.conversation)
  30. mail to: @me.user.email, subject: I18n.t('notification_mailer.favourite.subject', name: @account.acct)
  31. end
  32. end
  33. def reblog(recipient, notification)
  34. @me = recipient
  35. @account = notification.from_account
  36. @status = notification.target_status
  37. return unless @me.user.functional? && @status.present?
  38. locale_for_account(@me) do
  39. thread_by_conversation(@status.conversation)
  40. mail to: @me.user.email, subject: I18n.t('notification_mailer.reblog.subject', name: @account.acct)
  41. end
  42. end
  43. def follow_request(recipient, notification)
  44. @me = recipient
  45. @account = notification.from_account
  46. return unless @me.user.functional?
  47. locale_for_account(@me) do
  48. mail to: @me.user.email, subject: I18n.t('notification_mailer.follow_request.subject', name: @account.acct)
  49. end
  50. end
  51. private
  52. def thread_by_conversation(conversation)
  53. return if conversation.nil?
  54. msg_id = "<conversation-#{conversation.id}.#{conversation.created_at.strftime('%Y-%m-%d')}@#{Rails.configuration.x.local_domain}>"
  55. headers['In-Reply-To'] = msg_id
  56. headers['References'] = msg_id
  57. end
  58. end