Add antenna support for firefish

This commit is contained in:
KMY 2023-09-21 10:00:59 +09:00
parent 3ad86a9020
commit 80a55ed7c2
2 changed files with 63 additions and 2 deletions

View file

@ -47,8 +47,8 @@ class DeliveryAntennaService
end
antennas = antennas.where(account_id: Account.without_suspended.joins(:user).select('accounts.id').where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago))
antennas = antennas.where(account: @status.account.followers) if [:public, :public_unlisted, :login, :limited].exclude?(@status.visibility.to_sym) && !@status.public_searchability?
antennas = antennas.where(account: @status.mentioned_accounts) if @status.visibility.to_sym == :limited
antennas = antennas.where(account: @status.account.followers) if followers_only?
antennas = antennas.where(account: @status.mentioned_accounts) if mentioned_users_only?
antennas = antennas.where(with_media_only: false) unless @status.with_media?
antennas = antennas.where(ignore_reblog: false) if @status.reblog?
antennas = antennas.where(stl: false, ltl: false)
@ -116,6 +116,26 @@ class DeliveryAntennaService
collection.deliver!
end
def followers_only?
case @status.visibility.to_sym
when :public, :public_unlisted, :login, :limited
false
when :unlisted
if @status.local?
!@status.public_searchability?
else
info = InstanceInfo.find_by(domain: @status.account.domain)
info&.software == 'firefish' || !@status.public_searchability?
end
else
true
end
end
def mentioned_users_only?
@status.visibility.to_sym == :limited
end
class AntennaCollection
def initialize(status, update, stl_home = false) # rubocop:disable Style/OptionalBooleanParameter
@status = status

View file

@ -12,6 +12,7 @@ RSpec.describe DeliveryAntennaService, type: :service do
let(:domain) { nil }
let(:spoiler_text) { '' }
let(:tags) { Tag.find_or_create_by_names(['hoge']) }
let(:software) { nil }
let(:status) do
url = domain.present? ? 'https://example.com/status' : nil
status = Fabricate(:status, account: alice, spoiler_text: spoiler_text, visibility: visibility, searchability: searchability, text: 'Hello my body #hoge', url: url)
@ -30,6 +31,8 @@ RSpec.describe DeliveryAntennaService, type: :service do
let(:mode) { :home }
before do
Fabricate(:instance_info, domain: domain, software: software) if domain.present? && software.present?
bob.follow!(alice)
alice.block!(ohagi)
@ -359,4 +362,42 @@ RSpec.describe DeliveryAntennaService, type: :service do
expect(antenna_feed_of(antenna)).to include status.id
end
end
context 'with federated unlisted post' do
let(:visibility) { :unlisted }
let(:searchability) { :public }
let(:domain) { 'fast.example.com' }
let!(:antenna) { antenna_with_keyword(bob, 'body') }
let!(:empty_antenna) { antenna_with_keyword(tom, 'body') }
context 'when unknown domain' do
let(:software) { nil }
it 'detecting antenna' do
expect(antenna_feed_of(antenna)).to include status.id
expect(antenna_feed_of(empty_antenna)).to include status.id
end
end
context 'when misskey domain' do
let(:software) { 'misskey' }
it 'detecting antenna' do
expect(antenna_feed_of(antenna)).to include status.id
expect(antenna_feed_of(empty_antenna)).to include status.id
end
end
context 'when firefish domain' do
let(:software) { 'firefish' }
it 'detecting antenna' do
expect(antenna_feed_of(antenna)).to include status.id
end
it 'not detecting antenna' do
expect(antenna_feed_of(empty_antenna)).to_not include status.id
end
end
end
end