From b6ddc4fe278da4111aea8b1cbf34a07298d5323b Mon Sep 17 00:00:00 2001 From: Jonathan de Jong Date: Fri, 1 Dec 2023 10:49:05 +0100 Subject: [PATCH 1/3] Fix notifications interfering with exclusive lists --- app/lib/feed_manager.rb | 17 +++++++++++++---- app/workers/feed_insert_worker.rb | 7 +++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index 4e645a11f67..c41b55e85d0 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -40,9 +40,9 @@ class FeedManager def filter?(timeline_type, status, receiver) case timeline_type when :home - filter_from_home?(status, receiver.id, build_crutches(receiver.id, [status]), :home) + filter_from_home?(status, receiver.id, build_crutches(receiver.id, [status]), check_exclusive_list: true) when :list - filter_from_list?(status, receiver) || filter_from_home?(status, receiver.account_id, build_crutches(receiver.account_id, [status]), :list) + filter_from_list?(status, receiver) || filter_from_home?(status, receiver.account_id, build_crutches(receiver.account_id, [status]), check_exclusive_list: false) when :mentions filter_from_mentions?(status, receiver.id) when :tags @@ -52,6 +52,14 @@ class FeedManager end end + # Check if the status should be filtered from notifications + # @param [Status] status + # @param [Integer] account_id + # @return [Boolean] + def filter_notification?(account_id, status) + filter_from_home?(status, account_id, build_crutches(account_id, [status]), check_exclusive_list: false) + end + # Add a status to a home feed and send a streaming API update # @param [Account] account # @param [Status] status @@ -371,11 +379,12 @@ class FeedManager # @param [Status] status # @param [Integer] receiver_id # @param [Hash] crutches + # @param [Boolean] check_exclusive_list # @return [Boolean] - def filter_from_home?(status, receiver_id, crutches, timeline_type = :home) + def filter_from_home?(status, receiver_id, crutches, check_exclusive_list: true) return false if receiver_id == status.account_id return true if status.reply? && (status.in_reply_to_id.nil? || status.in_reply_to_account_id.nil?) - return true if timeline_type != :list && crutches[:exclusive_list_users][status.account_id].present? + return true if check_exclusive_list && crutches[:exclusive_list_users][status.account_id].present? return true if crutches[:languages][status.account_id].present? && status.language.present? && !crutches[:languages][status.account_id].include?(status.language) check_for_blocks = crutches[:active_mentions][status.id] || [] diff --git a/app/workers/feed_insert_worker.rb b/app/workers/feed_insert_worker.rb index fd7dbd30dab..11a79c629f3 100644 --- a/app/workers/feed_insert_worker.rb +++ b/app/workers/feed_insert_worker.rb @@ -33,8 +33,9 @@ class FeedInsertWorker perform_unpush if update? else perform_push - perform_notify if notify? end + + perform_notify if notify? end def feed_filtered? @@ -49,7 +50,9 @@ class FeedInsertWorker end def notify? - return false if @type != :home || @status.reblog? || (@status.reply? && @status.in_reply_to_account_id != @status.account_id) + return false if @type != :home || @status.reblog? || + (@status.reply? && @status.in_reply_to_account_id != @status.account_id) || + FeedManager.instance.filter_notification?(@status.account_id, @status) Follow.find_by(account: @follower, target_account: @status.account)&.notify? end From 700dfac4cbb5d43a19dc73c68e59298dc726e1ed Mon Sep 17 00:00:00 2001 From: Jonathan de Jong Date: Fri, 1 Dec 2023 11:17:25 +0100 Subject: [PATCH 2/3] fix rubocop --- app/workers/feed_insert_worker.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/workers/feed_insert_worker.rb b/app/workers/feed_insert_worker.rb index 11a79c629f3..41e24f798ce 100644 --- a/app/workers/feed_insert_worker.rb +++ b/app/workers/feed_insert_worker.rb @@ -51,8 +51,8 @@ class FeedInsertWorker def notify? return false if @type != :home || @status.reblog? || - (@status.reply? && @status.in_reply_to_account_id != @status.account_id) || - FeedManager.instance.filter_notification?(@status.account_id, @status) + (@status.reply? && @status.in_reply_to_account_id != @status.account_id) || + FeedManager.instance.filter_notification?(@status.account_id, @status) Follow.find_by(account: @follower, target_account: @status.account)&.notify? end From 1d494abc6f5b9b37a3b45ad99d2187094f3bcd28 Mon Sep 17 00:00:00 2001 From: Jonathan de Jong Date: Fri, 1 Dec 2023 11:36:34 +0100 Subject: [PATCH 3/3] fix tests --- spec/workers/feed_insert_worker_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/workers/feed_insert_worker_spec.rb b/spec/workers/feed_insert_worker_spec.rb index e9484879ff4..8579cc4ce7a 100644 --- a/spec/workers/feed_insert_worker_spec.rb +++ b/spec/workers/feed_insert_worker_spec.rb @@ -32,7 +32,7 @@ describe FeedInsertWorker do context 'when there are real records' do it 'skips the push when there is a filter' do - instance = instance_double(FeedManager, push_to_home: nil, filter?: true) + instance = instance_double(FeedManager, push_to_home: nil, filter?: true, filter_notification?: true) allow(FeedManager).to receive(:instance).and_return(instance) result = subject.perform(status.id, follower.id) @@ -41,7 +41,7 @@ describe FeedInsertWorker do end it 'pushes the status onto the home timeline without filter' do - instance = instance_double(FeedManager, push_to_home: nil, filter?: false) + instance = instance_double(FeedManager, push_to_home: nil, filter?: false, filter_notification?: false) allow(FeedManager).to receive(:instance).and_return(instance) result = subject.perform(status.id, follower.id, :home)