logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

notification_mailer.rb (2838B)


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