about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-06-05 10:07:44 -0400
committerEugen Rochko <eugen@zeonfederated.com>2017-06-05 16:07:44 +0200
commit6201f96b8a49d58b5b2d73fac9fa1fa93f5890ed (patch)
tree57e2f3b751dab120705459f5b9d9c39e2f7e63bb /app/lib
parentc26cea262b7673b0b239dd1da6754e7788aa08d8 (diff)
Introduce StatusThreadingConcern (#3490)
* Add a StatusFilter class to identify visibility of statuses by accounts

* Extract StatusThreadingConcern from Status

* Clarify purpose of checking for nil account
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/status_filter.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/app/lib/status_filter.rb b/app/lib/status_filter.rb
new file mode 100644
index 000000000..89d45d442
--- /dev/null
+++ b/app/lib/status_filter.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+class StatusFilter
+  attr_reader :status, :account
+
+  def initialize(status, account)
+    @status = status
+    @account = account
+  end
+
+  def filtered?
+    account_present? && filtered_status?
+  end
+
+  private
+
+  def account_present?
+    !account.nil?
+  end
+
+  def filtered_status?
+    blocking_account? || blocking_domain? || muting_account? || silenced_account? || blocked_by_policy?
+  end
+
+  def blocking_account?
+    account.blocking? status.account_id
+  end
+
+  def blocking_domain?
+    account.domain_blocking? status.account_domain
+  end
+
+  def muting_account?
+    account.muting? status.account_id
+  end
+
+  def silenced_account?
+    status_account_silenced? && !account_following_status_account?
+  end
+
+  def status_account_silenced?
+    status.account.silenced?
+  end
+
+  def account_following_status_account?
+    account.following? status.account_id
+  end
+
+  def blocked_by_policy?
+    !policy_allows_show?
+  end
+
+  def policy_allows_show?
+    StatusPolicy.new(account, status).show?
+  end
+end