]> cat aescling's git repositories - mastodon.git/commitdiff
Fix #65 - Options to block notifications from people you don't follow/who don't follo...
authorEugen Rochko <eugen@zeonfederated.com>
Fri, 25 Nov 2016 12:13:16 +0000 (13:13 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Fri, 25 Nov 2016 12:13:16 +0000 (13:13 +0100)
app/controllers/settings/preferences_controller.rb
app/lib/feed_manager.rb
app/models/user.rb
app/services/notify_service.rb
app/views/settings/preferences/show.html.haml
config/i18n-tasks.yml
config/locales/simple_form.de.yml
config/locales/simple_form.en.yml

index 5be8719aef9a0a8a130d9a64694a848e4c608e0e..cacc03b65f0673b02bbb93269fbd9d1fcfd717a4 100644 (file)
@@ -14,7 +14,10 @@ class Settings::PreferencesController < ApplicationController
     current_user.settings(:notification_emails).favourite = user_params[:notification_emails][:favourite] == '1'
     current_user.settings(:notification_emails).mention   = user_params[:notification_emails][:mention]   == '1'
 
-    if current_user.update(user_params.except(:notification_emails))
+    current_user.settings(:interactions).must_be_follower  = user_params[:interactions][:must_be_follower]  == '1'
+    current_user.settings(:interactions).must_be_following = user_params[:interactions][:must_be_following] == '1'
+
+    if current_user.update(user_params.except(:notification_emails, :interactions))
       redirect_to settings_preferences_path, notice: I18n.t('generic.changes_saved_msg')
     else
       render action: :show
@@ -24,6 +27,6 @@ class Settings::PreferencesController < ApplicationController
   private
 
   def user_params
-    params.require(:user).permit(:locale, notification_emails: [:follow, :reblog, :favourite, :mention])
+    params.require(:user).permit(:locale, notification_emails: [:follow, :reblog, :favourite, :mention], interactions: [:must_be_follower, :must_be_following])
   end
 end
index 81489365e911a5763b62c32ceef083a6a6ec7a86..b812ad1f4e1d0e6d0305d625a8f1369d8b7100ef 100644 (file)
@@ -84,7 +84,7 @@ class FeedManager
   def filter_from_mentions?(status, receiver)
     should_filter   = receiver.id == status.account_id                      # Filter if I'm mentioning myself
     should_filter ||= receiver.blocking?(status.account)                    # or it's from someone I blocked
-    should_filter ||= receiver.blocking?(status.mentions.map(&:account_id)) # or if it mentions someone I blocked
+    should_filter ||= receiver.blocking?(status.mentions.includes(:account).map(&:account)) # or if it mentions someone I blocked
 
     if status.reply? && !status.thread.account.nil?                         # or it's a reply
       should_filter ||= receiver.blocking?(status.thread.account)           # to a user I blocked
@@ -95,7 +95,7 @@ class FeedManager
 
   def filter_from_public?(status, receiver)
     should_filter   = receiver.blocking?(status.account)
-    should_filter ||= receiver.blocking?(status.mentions.map(&:account_id))
+    should_filter ||= receiver.blocking?(status.mentions.includes(:account).map(&:account))
 
     if status.reply? && !status.thread.account.nil?
       should_filter ||= receiver.blocking?(status.thread.account)
index 366172e9a09cbf9eeb1936f97b6297e6fb019bda..423833d471cd86fd0fc4335a28a26e46cfeb5294 100644 (file)
@@ -15,6 +15,7 @@ class User < ApplicationRecord
 
   has_settings do |s|
     s.key :notification_emails, defaults: { follow: false, reblog: false, favourite: false, mention: false }
+    s.key :interactions, defaults: { must_be_follower: false, must_be_following: false }
   end
 
   def send_devise_notification(notification, *args)
index 772adfb90bee4b03f86f7fc0e02029688dd69984..1efd326b090d6ea79b9facd91072bc6d06aa7935 100644 (file)
@@ -36,6 +36,8 @@ class NotifyService < BaseService
     blocked   = false
     blocked ||= @recipient.id == @notification.from_account.id
     blocked ||= @recipient.blocking?(@notification.from_account)
+    blocked ||= (@recipient.user.settings(:interactions).must_be_follower  && !@notification.from_account.following?(@recipient))
+    blocked ||= (@recipient.user.settings(:interactions).must_be_following && !@recipient.following?(@notification.from_account))
     blocked ||= send("blocked_#{@notification.type}?")
     blocked
   end
index 693702ff73d001962d7ea891949e02d3cb9d1ee5..db5b9fb48f42ea6492bed96cb0da5a1e2fe0cec9 100644 (file)
     = ff.input :favourite, as: :boolean, wrapper: :with_label
     = ff.input :mention, as: :boolean, wrapper: :with_label
 
+  = f.simple_fields_for :interactions, current_user.settings(:interactions) do |ff|
+    = ff.input :must_be_follower, as: :boolean, wrapper: :with_label
+    = ff.input :must_be_following, as: :boolean, wrapper: :with_label
+
   .actions
     = f.button :button, t('generic.save_changes'), type: :submit
 
index d345ce6c06b1d03d15920c24c9209ccd10a79970..4dc6985b75ea6ba30a1c9e0234c3c9856986c9a6 100644 (file)
@@ -30,9 +30,6 @@ search:
     - app/assets/fonts
     - app/assets/videos
 
-ignore_missing:
-  - '{devise,simple_form}.*'
-
 ignore_unused:
   - 'activerecord.attributes.*'
   - '{devise,will_paginate,doorkeeper}.*'
index 36c5141a2c56c406bd510b656e5c9dbf35609330..90aeb1e5cde6b6d41d940bf558ec8fa0b3dd70e7 100644 (file)
@@ -21,6 +21,9 @@ de:
         follow: E-mail senden, wenn mir jemand folgt
         mention: E-mail senden, wenn mich jemand erwähnt
         reblog: E-mail senden, wenn jemand meinen Beitrag teilt
+      interactions:
+        must_be_follower: Benachrichtigungen von nicht-Folgern blockieren
+        must_be_following: Benachrichtigungen von Nutzern blockieren, denen ich nicht folge
     'no': Nein
     required:
       mark: "*"
index a7d958c06d7e2703f104aeb582970fa7ef46a2ac..1ba7c91e2b2c9fc48926319a4e6f43a7305971c2 100644 (file)
@@ -21,6 +21,9 @@ en:
         follow: Send e-mail when someone follows you
         mention: Send e-mail when someone mentions you
         reblog: Send e-mail when someone reblogs your status
+      interactions:
+        must_be_follower: Block notifications from non-followers
+        must_be_following: Block notifications from people you don't follow
     'no': 'No'
     required:
       mark: "*"