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.

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