From e3ed212b859a7bec6b26c3d52e6f7ea14069f76d Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 25 Nov 2016 12:35:21 +0100 Subject: [PATCH] Filter statuses that mention blocked users --- app/lib/feed_manager.rb | 26 +++++++++++++++----------- app/models/account.rb | 4 ++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index c8512476d..81489365e 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -68,30 +68,34 @@ class FeedManager def filter_from_home?(status, receiver) should_filter = false - if status.reply? && !status.thread.account.nil? # Filter out if it's a reply - should_filter = !receiver.following?(status.thread.account) # and I'm not following the person it's a reply to - should_filter &&= !(receiver.id == status.thread.account_id) # and it's not a reply to me - should_filter &&= !(status.account_id == status.thread.account_id) # and it's not a self-reply - elsif status.reblog? # Filter out a reblog - should_filter = receiver.blocking?(status.reblog.account) # if I'm blocking the reblogged person + if status.reply? && !status.thread.account.nil? # Filter out if it's a reply + should_filter = !receiver.following?(status.thread.account) # and I'm not following the person it's a reply to + should_filter &&= !(receiver.id == status.thread.account_id) # and it's not a reply to me + should_filter &&= !(status.account_id == status.thread.account_id) # and it's not a self-reply + elsif status.reblog? # Filter out a reblog + should_filter = receiver.blocking?(status.reblog.account) # if I'm blocking the reblogged person end + should_filter ||= receiver.blocking?(status.mentions.map(&:account_id)) # or if it mentions someone I blocked + should_filter end def filter_from_mentions?(status, receiver) - should_filter = receiver.id == status.account_id # Filter if I'm mentioning myself - should_filter ||= receiver.blocking?(status.account) # or it's from someone I blocked + should_filter = receiver.id == status.account_id # Filter if I'm mentioning myself + should_filter ||= receiver.blocking?(status.account) # or it's from someone I blocked + should_filter ||= receiver.blocking?(status.mentions.map(&:account_id)) # or if it mentions someone I blocked - if status.reply? && !status.thread.account.nil? # or it's a reply - should_filter ||= receiver.blocking?(status.thread.account) # to a user I blocked + if status.reply? && !status.thread.account.nil? # or it's a reply + should_filter ||= receiver.blocking?(status.thread.account) # to a user I blocked end should_filter end def filter_from_public?(status, receiver) - should_filter = receiver.blocking?(status.account) + should_filter = receiver.blocking?(status.account) + should_filter ||= receiver.blocking?(status.mentions.map(&:account_id)) if status.reply? && !status.thread.account.nil? should_filter ||= receiver.blocking?(status.thread.account) diff --git a/app/models/account.rb b/app/models/account.rb index a60a23e14..870de8b7c 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -66,12 +66,12 @@ class Account < ApplicationRecord def unfollow!(other_account) follow = active_relationships.find_by(target_account: other_account) - follow.destroy unless follow.nil? + follow&.destroy end def unblock!(other_account) block = block_relationships.find_by(target_account: other_account) - block.destroy unless block.nil? + block&.destroy end def following?(other_account)