about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorysksn <bluewhale1982@gmail.com>2020-01-11 19:55:33 +0900
committermultiple creatures <dev@multiple-creature.party>2020-02-27 13:30:57 -0600
commit856c36af97c1f12013532a382ed9a44c1f97d6ac (patch)
treef27fdefbae32cb7c0de2dc077f089dc5e68830b4 /app/models
parentdf1c0bc8537dd57c10040925fac62f7acb785736 (diff)
port tootsuite#9626 to monsterfork: Refactor StatusThreadingConcern
* Remove #filter_from_context?

* Create scope Status.with_accounts

Retrieving AR objects should be
their model's scope
Diffstat (limited to 'app/models')
-rw-r--r--app/models/concerns/status_threading_concern.rb13
-rw-r--r--app/models/status.rb1
2 files changed, 3 insertions, 11 deletions
diff --git a/app/models/concerns/status_threading_concern.rb b/app/models/concerns/status_threading_concern.rb
index adf8659d3..9cbf0cda6 100644
--- a/app/models/concerns/status_threading_concern.rb
+++ b/app/models/concerns/status_threading_concern.rb
@@ -81,12 +81,12 @@ module StatusThreadingConcern
   end
 
   def find_statuses_from_tree_path(ids, account, promote: false)
-    statuses    = statuses_with_accounts(ids).to_a
+    statuses    = Status.with_accounts(ids).to_a
     account_ids = statuses.map(&:account_id).uniq
     domains     = statuses.map(&:account_domain).compact.uniq
     relations   = relations_map_for_account(account, account_ids, domains)
 
-    statuses.reject! { |status| filter_from_context?(status, account, relations) }
+    statuses.reject! { |status| StatusFilter.new(status, account, relations).filtered? }
 
     # Order ancestors/descendants by tree path
     statuses.sort_by! { |status| ids.index(status.id) }
@@ -125,13 +125,4 @@ module StatusThreadingConcern
       domain_blocking_by_domain: Account.domain_blocking_map_by_domain(domains, account.id),
     }
   end
-
-  def statuses_with_accounts(ids)
-    kicked_accounts = ConversationKick.select(:account_id).where(conversation_id: self.conversation_id)
-    Status.where(id: ids).where.not(account_id: kicked_accounts).includes(:account)
-  end
-
-  def filter_from_context?(status, account, relations)
-    StatusFilter.new(status, account, relations).filtered?
-  end
 end
diff --git a/app/models/status.rb b/app/models/status.rb
index c61bc0a5f..05061bce1 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -104,6 +104,7 @@ class Status < ApplicationRecord
   scope :curated, -> { where(curated: true) }
   scope :hidden, -> { where(hidden: true) }
 
+  scope :with_accounts, ->(ids) { where(id: ids).includes(:account) }
   scope :without_replies, -> { where('statuses.reply = FALSE OR statuses.in_reply_to_account_id = statuses.account_id') }
   scope :without_reblogs, -> { where('statuses.reblog_of_id IS NULL') }
   scope :reblogs, -> { where('statuses.reblog_of_id IS NOT NULL') } # all reblogs