about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-02-16 22:13:00 +0000
committermultiple creatures <dev@multiple-creature.party>2019-05-21 03:16:21 -0500
commit28c9b9ce6a56a06a4c6e2e5192b1984d99ee9047 (patch)
treea75da71366a322b544ef696e65487fce4a58fc01 /app
parent10b20607aced6ffe541b2d33af2b450fe6803992 (diff)
improve filtering
Diffstat (limited to 'app')
-rw-r--r--app/lib/status_filter.rb47
-rw-r--r--app/models/status.rb6
-rw-r--r--app/policies/status_policy.rb8
3 files changed, 28 insertions, 33 deletions
diff --git a/app/lib/status_filter.rb b/app/lib/status_filter.rb
index 4253f6502..b50057c24 100644
--- a/app/lib/status_filter.rb
+++ b/app/lib/status_filter.rb
@@ -11,7 +11,9 @@ class StatusFilter
 
   def filtered?
     return false if !account.nil? && account.id == status.account_id
-    blocked_by_policy? || (account_present? && filtered_status?) || silenced_account?
+    return true if blocked_by_policy? || (account_present? && filtered_status?) || silenced_account?
+    # filter non-op posts replying to something marked no replies
+    non_self_reply? && reply_to_no_replies?
   end
 
   private
@@ -25,13 +27,11 @@ class StatusFilter
   end
 
   def filtered_reference?
-    filtered_reply = reply_to_blocked? || reply_to_muted?
-
-    # I don't think this should happen, but just in case...
-    return filtered_reply if status&.mentions.nil?
+    # filter muted/blocked
+    return true if reply_to_blocked? || reply_to_muted?
 
-    # filter non-op posts replying to something marked no replies
-    return true if reply_to_no_replies?
+    # kajiht has no filters if status has no mentions
+    return false if status&.mentions.nil?
 
     # Grab a list of account IDs mentioned in the status.
     mentioned_account_ids = status.mentions.pluck(:account_id)
@@ -39,22 +39,16 @@ class StatusFilter
     # Don't filter statuses mentioning you.
     return false if mentioned_account_ids.include?(account.id)
 
-    # Otherwise, filter replies to someone you've muted or blocked.
-    return true if filtered_reply
-
-    # Otherwise, filter the status if it mentions someone in the preloaded muting relation.
+    # Otherwise, filter the status if it mentions someone you've muted.
     return true if @preloaded_relations[:muting] && mentioned_account_ids.any? do |mentioned_account_id|
       @preloaded_relations[:muting][mentioned_account_id]
     end
-
-    # Otherwise, filter the status if it mentions someone you've muted.
     return true if account.muting?(mentioned_account_ids)
 
     # Same as above, but for blocks:
     return true if @preloaded_relations[:blocking] && mentioned_account_ids.any? do |mentioned_account_id|
       @preloaded_relations[:blocking][mentioned_account_id]
     end
-
     account.blocking?(mentioned_account_ids)
   end
 
@@ -66,14 +60,6 @@ class StatusFilter
     @preloaded_relations[:muting] ? @preloaded_relations[:muting][status.in_reply_to_account_id] : account.muting?(status.in_reply_to_account_id)
   end
 
-  def reply_to_no_replies?
-    status.reply? &&
-      !status.in_reply_to_account_id.nil? &&
-      !status.in_reply_to_id.nil? &&
-      status.account_id != status.in_reply_to_account_id &&
-      Status.find(status.in_reply_to_id)&.marked_no_replies?
-  end
-
   def blocking_account?
     @preloaded_relations[:blocking] ? @preloaded_relations[:blocking][status.account_id] : account.blocking?(status.account_id)
   end
@@ -86,6 +72,19 @@ class StatusFilter
     @preloaded_relations[:muting] ? @preloaded_relations[:muting][status.account_id] : account.muting?(status.account_id)
   end
 
+  def account_following_status_account?
+    @preloaded_relations[:following] ? @preloaded_relations[:following][status.account_id] : account&.following?(status.account_id)
+  end
+
+  def non_self_reply?
+    status.reply? && status.in_reply_to_account_id != status.account_id
+  end
+
+  def reply_to_no_replies?
+    parent_status = Status.find(status.in_reply_to_id)
+    parent_status&.marked_no_replies? && !parent_status.mentions.pluck(:account_id).include?(status.account_id)
+  end
+
   def silenced_account?
     !account&.silenced? && status_account_silenced? && !account_following_status_account?
   end
@@ -94,10 +93,6 @@ class StatusFilter
     status.account.silenced?
   end
 
-  def account_following_status_account?
-    @preloaded_relations[:following] ? @preloaded_relations[:following][status.account_id] : account&.following?(status.account_id)
-  end
-
   def blocked_by_policy?
     !policy_allows_show?
   end
diff --git a/app/models/status.rb b/app/models/status.rb
index 157986e24..80a3c8208 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -295,7 +295,7 @@ class Status < ApplicationRecord
 
   after_create :set_poll_id
 
-  after_find :limit_visibility
+  after_find :limit_domain_visibility
 
   class << self
     def selectable_visibilities
@@ -551,11 +551,11 @@ class Status < ApplicationRecord
     self.sensitive  = false if sensitive.nil?
   end
 
-  def limit_visibility
+  def limit_domain_visibility
     return unless has_attribute?(:uri) && !uri.nil?
     domain = Addressable::URI.parse(uri).host
     self.sensitive = true if domain.in?(FORCE_SENSITIVE)
-    self.visibility = :unlisted if domain.in?(FORCE_UNLISTED)
+    self.visibility = :unlisted if public_visibility? && domain.in?(FORCE_UNLISTED)
   end
 
   def set_locality
diff --git a/app/policies/status_policy.rb b/app/policies/status_policy.rb
index 5e3282681..fcf19db62 100644
--- a/app/policies/status_policy.rb
+++ b/app/policies/status_policy.rb
@@ -14,7 +14,7 @@ class StatusPolicy < ApplicationPolicy
   def show?
     return false if local_only? && (current_account.nil? || !current_account.local?)
 
-    if requires_mention?
+    if direct?
       owned? || mention_exists?
     elsif private?
       owned? || following_author? || mention_exists?
@@ -24,7 +24,7 @@ class StatusPolicy < ApplicationPolicy
   end
 
   def reblog?
-    !requires_mention? && (!private? || owned?) && show? && !blocking_author?
+    !direct? && (!private? || owned?) && show? && !blocking_author?
   end
 
   def favourite?
@@ -43,8 +43,8 @@ class StatusPolicy < ApplicationPolicy
 
   private
 
-  def requires_mention?
-    record.direct_visibility? || record.limited_visibility?
+  def direct?
+    record.direct_visibility?
   end
 
   def owned?