about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-10-07 13:17:56 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-10-07 13:17:56 +0200
commit06016453bd91882a53e91c11fc80f2c75fd474bb (patch)
tree1effbffae4db31206aff69efecb431407f70a924 /app
parent943c69c65d6410d1689d4494c9214c90654db56b (diff)
Adding user settings (model and mailer), no form yet
Diffstat (limited to 'app')
-rw-r--r--app/mailers/notification_mailer.rb5
-rw-r--r--app/models/user.rb4
2 files changed, 8 insertions, 1 deletions
diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb
index 1414c2295..6c81df269 100644
--- a/app/mailers/notification_mailer.rb
+++ b/app/mailers/notification_mailer.rb
@@ -1,11 +1,11 @@
 class NotificationMailer < ApplicationMailer
   helper StreamEntriesHelper
-  helper AtomBuilderHelper
 
   def mention(mentioned_account, status)
     @me     = mentioned_account
     @status = status
 
+    return unless @me.user.settings(:notification_emails).mention
     mail to: @me.user.email, subject: "You were mentioned by #{@status.account.acct}"
   end
 
@@ -13,6 +13,7 @@ class NotificationMailer < ApplicationMailer
     @me      = followed_account
     @account = follower
 
+    return unless @me.user.settings(:notification_emails).follow
     mail to: @me.user.email, subject: "#{@account.acct} is now following you"
   end
 
@@ -21,6 +22,7 @@ class NotificationMailer < ApplicationMailer
     @account = from_account
     @status  = target_status
 
+    return unless @me.user.settings(:notification_emails).favourite
     mail to: @me.user.email, subject: "#{@account.acct} favourited your status"
   end
 
@@ -29,6 +31,7 @@ class NotificationMailer < ApplicationMailer
     @account = from_account
     @status  = target_status
 
+    return unless @me.user.settings(:notification_emails).reblog
     mail to: @me.user.email, subject: "#{@account.acct} reblogged your status"
   end
 end
diff --git a/app/models/user.rb b/app/models/user.rb
index c1243e9ac..bd5512a31 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -9,4 +9,8 @@ class User < ApplicationRecord
   scope :prolific, -> { joins('inner join statuses on statuses.account_id = users.account_id').select('users.*, count(statuses.id) as statuses_count').group('users.id').order('statuses_count desc') }
   scope :recent,   -> { order('created_at desc') }
   scope :admins,   -> { where(admin: true) }
+
+  has_settings do |s|
+    s.key :notification_emails, defaults: { follow: true, reblog: true, favourite: true, mention: true }
+  end
 end