Remove statuses from antenna timeline when blocked
This commit is contained in:
parent
e336542063
commit
21e590c02b
4 changed files with 53 additions and 0 deletions
|
@ -265,6 +265,28 @@ class FeedManager
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def clear_from_antenna(antenna, target_account)
|
||||||
|
timeline_key = key(:antenna, antenna.id)
|
||||||
|
timeline_status_ids = redis.zrange(timeline_key, 0, -1)
|
||||||
|
statuses = Status.where(id: timeline_status_ids).select(:id, :reblog_of_id, :account_id).to_a
|
||||||
|
reblogged_ids = Status.where(id: statuses.filter_map(&:reblog_of_id), account: target_account).pluck(:id)
|
||||||
|
with_mentions_ids = Mention.active.where(status_id: statuses.flat_map { |s| [s.id, s.reblog_of_id] }.compact, account: target_account).pluck(:status_id)
|
||||||
|
|
||||||
|
target_statuses = statuses.select do |status|
|
||||||
|
status.account_id == target_account.id || reblogged_ids.include?(status.reblog_of_id) || with_mentions_ids.include?(status.id) || with_mentions_ids.include?(status.reblog_of_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
target_statuses.each do |status|
|
||||||
|
unpush_from_antenna(antenna, status)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def clear_from_antennas(account, target_account)
|
||||||
|
Antenna.where(account: account).each do |antenna|
|
||||||
|
clear_from_antenna(antenna, target_account)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Populate home feed of account from scratch
|
# Populate home feed of account from scratch
|
||||||
# @param [Account] account
|
# @param [Account] account
|
||||||
# @return [void]
|
# @return [void]
|
||||||
|
|
|
@ -7,6 +7,7 @@ class AfterBlockService < BaseService
|
||||||
|
|
||||||
clear_home_feed!
|
clear_home_feed!
|
||||||
clear_list_feeds!
|
clear_list_feeds!
|
||||||
|
clear_antenna_feeds!
|
||||||
clear_notifications!
|
clear_notifications!
|
||||||
clear_conversations!
|
clear_conversations!
|
||||||
end
|
end
|
||||||
|
@ -21,6 +22,10 @@ class AfterBlockService < BaseService
|
||||||
FeedManager.instance.clear_from_lists(@account, @target_account)
|
FeedManager.instance.clear_from_lists(@account, @target_account)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def clear_antenna_feeds!
|
||||||
|
FeedManager.instance.clear_from_antennas(@account, @target_account)
|
||||||
|
end
|
||||||
|
|
||||||
def clear_conversations!
|
def clear_conversations!
|
||||||
AccountConversation.where(account: @account).where('? = ANY(participant_account_ids)', @target_account.id).in_batches.destroy_all
|
AccountConversation.where(account: @account).where('? = ANY(participant_account_ids)', @target_account.id).in_batches.destroy_all
|
||||||
end
|
end
|
||||||
|
|
7
spec/fabricators/antenna_fabricator.rb
Normal file
7
spec/fabricators/antenna_fabricator.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
Fabricator(:antenna) do
|
||||||
|
account { Fabricate.build(:account) }
|
||||||
|
title 'MyString'
|
||||||
|
list_id 0
|
||||||
|
end
|
|
@ -48,4 +48,23 @@ RSpec.describe AfterBlockService, type: :service do
|
||||||
}.from([status.id.to_s, other_account_status.id.to_s, other_account_reblog.id.to_s]).to([other_account_status.id.to_s])
|
}.from([status.id.to_s, other_account_status.id.to_s, other_account_reblog.id.to_s]).to([other_account_status.id.to_s])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'antennas' do
|
||||||
|
let(:antenna) { Fabricate(:antenna, account: account, list_id: 0) }
|
||||||
|
let(:antenna_timeline_key) { FeedManager.instance.key(:antenna, antenna.id) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
redis.del(antenna_timeline_key)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "clears account's statuses" do
|
||||||
|
FeedManager.instance.push_to_antenna(antenna, status)
|
||||||
|
FeedManager.instance.push_to_antenna(antenna, other_account_status)
|
||||||
|
FeedManager.instance.push_to_antenna(antenna, other_account_reblog)
|
||||||
|
|
||||||
|
expect { subject }.to change {
|
||||||
|
redis.zrange(antenna_timeline_key, 0, -1)
|
||||||
|
}.from([status.id.to_s, other_account_status.id.to_s, other_account_reblog.id.to_s]).to([other_account_status.id.to_s])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue