about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-11-15 17:33:41 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-11-15 17:33:41 +0100
commit4f07fb1f0aee6d37d8b3c5fe0088cf36b3926372 (patch)
treeac2eb444dab54dbb84a9e712149d280088441a3d
parentfdc17bea58f210f62ac0d9e836b68e84c6dbd15c (diff)
Fix #144 - Filter statuses from blocked users out of ancestors/descendants results
-rw-r--r--app/controllers/api/v1/statuses_controller.rb2
-rw-r--r--app/models/status.rb12
2 files changed, 9 insertions, 5 deletions
diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb
index e1a417129..53578b2f7 100644
--- a/app/controllers/api/v1/statuses_controller.rb
+++ b/app/controllers/api/v1/statuses_controller.rb
@@ -12,7 +12,7 @@ class Api::V1::StatusesController < ApiController
   end
 
   def context
-    @context = OpenStruct.new(ancestors: @status.ancestors, descendants: @status.descendants)
+    @context = OpenStruct.new(ancestors: @status.ancestors(current_account), descendants: @status.descendants(current_account))
     set_maps([@status] + @context[:ancestors] + @context[:descendants])
   end
 
diff --git a/app/models/status.rb b/app/models/status.rb
index c6f5c8d6c..56f52975d 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -66,18 +66,22 @@ class Status < ApplicationRecord
     attributes['favourites_count'] || favourites.count
   end
 
-  def ancestors
+  def ancestors(account = nil)
     ids      = (Status.find_by_sql(['WITH RECURSIVE search_tree(id, in_reply_to_id, path) AS (SELECT id, in_reply_to_id, ARRAY[id] FROM statuses WHERE id = ? UNION ALL SELECT statuses.id, statuses.in_reply_to_id, path || statuses.id FROM search_tree JOIN statuses ON statuses.id = search_tree.in_reply_to_id WHERE NOT statuses.id = ANY(path)) SELECT id FROM search_tree ORDER BY path DESC', id]) - [self]).pluck(:id)
     statuses = Status.where(id: ids).with_counters.with_includes.group_by(&:id)
+    results  = ids.map { |id| statuses[id].first }
+    results  = results.reject { |status| account.blocking?(status.account) } unless account.nil?
 
-    ids.map { |id| statuses[id].first }
+    results
   end
 
-  def descendants
+  def descendants(account = nil)
     ids      = (Status.find_by_sql(['WITH RECURSIVE search_tree(id, path) AS (SELECT id, ARRAY[id] FROM statuses WHERE id = ? UNION ALL SELECT statuses.id, path || statuses.id FROM search_tree JOIN statuses ON statuses.in_reply_to_id = search_tree.id WHERE NOT statuses.id = ANY(path)) SELECT id FROM search_tree ORDER BY path', id]) - [self]).pluck(:id)
     statuses = Status.where(id: ids).with_counters.with_includes.group_by(&:id)
+    results  = ids.map { |id| statuses[id].first }
+    results  = results.reject { |status| account.blocking?(status.account) } unless account.nil?
 
-    ids.map { |id| statuses[id].first }
+    results
   end
 
   class << self