about summary refs log tree commit diff
path: root/app/mailers
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-03-03 23:45:48 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-03-04 00:00:48 +0100
commit6b81d100306259cd17b38d3f0f9dec0f0fb5b5d9 (patch)
treea6d40da1644804061eaeacdfd748d027aac2c41b /app/mailers
parentf5457cc3d2be79525d339dd5a5c046de6d0acf9d (diff)
Add digest e-mails
Diffstat (limited to 'app/mailers')
-rw-r--r--app/mailers/notification_mailer.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb
index a1b084682..bf4c16e43 100644
--- a/app/mailers/notification_mailer.rb
+++ b/app/mailers/notification_mailer.rb
@@ -49,4 +49,17 @@ class NotificationMailer < ApplicationMailer
       mail to: @me.user.email, subject: I18n.t('notification_mailer.follow_request.subject', name: @account.acct)
     end
   end
+
+  def digest(recipient, opts = {})
+    @me            = recipient
+    @since         = opts[:since] || @me.user.last_emailed_at || @me.user.current_sign_in_at
+    @notifications = Notification.where(account: @me, activity_type: 'Mention').where('created_at > ?', @since)
+    @follows_since = Notification.where(account: @me, activity_type: 'Follow').where('created_at > ?', @since).count
+
+    return if @notifications.empty?
+
+    I18n.with_locale(@me.user.locale || I18n.default_locale) do
+      mail to: @me.user.email, subject: I18n.t('notification_mailer.digest.subject', count: @notifications.size)
+    end
+  end
 end