From 2195bd5a9082be01e4b81c47d0053b76fdf90d26 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 2 May 2022 16:26:37 +0200 Subject: [PATCH] Change threading context code to filter out blocked replies on view --- .../concerns/status/threading_concern.rb | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/app/models/concerns/status/threading_concern.rb b/app/models/concerns/status/threading_concern.rb index 478a139d63..937090ead1 100644 --- a/app/models/concerns/status/threading_concern.rb +++ b/app/models/concerns/status/threading_concern.rb @@ -73,15 +73,26 @@ module Status::ThreadingConcern limit += 1 if limit.present? descendants_with_self = Status.find_by_sql([<<-SQL.squish, id: id, limit: limit, depth: depth]) - WITH RECURSIVE search_tree(id, path) AS ( - SELECT id, ARRAY[id] - FROM statuses - WHERE id = :id + WITH RECURSIVE search_tree(id, path, authors) AS ( + SELECT + id, ARRAY[id], ARRAY[account_id] + FROM + statuses + WHERE + id = :id + UNION ALL - SELECT statuses.id, path || statuses.id - FROM search_tree - JOIN statuses ON statuses.in_reply_to_id = search_tree.id - WHERE COALESCE(array_length(path, 1) < :depth, TRUE) AND NOT statuses.id = ANY(path) + + SELECT + statuses.id, path || statuses.id, authors || statuses.account_id + FROM + search_tree + JOIN + statuses ON statuses.in_reply_to_id = search_tree.id + WHERE + COALESCE(array_length(path, 1) < :depth, TRUE) AND NOT statuses.id = ANY(path) + AND NOT EXISTS (SELECT 1 FROM blocks WHERE target_account_id = statuses.account_id AND account_id = any(authors)) + AND NOT EXISTS (SELECT 1 FROM account_domain_blocks b JOIN accounts a ON a.domain = b.domain WHERE a.id = statuses.account_id AND b.account_id = any(authors)) ) SELECT id FROM search_tree