Skip to content

Commit

Permalink
Add: #62 ローカルタイムラインを無効にする管理者設定(内部挙動のみ)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Oct 25, 2023
1 parent 1218434 commit f889926
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 7 deletions.
2 changes: 2 additions & 0 deletions app/helpers/kmyblue_capabilities_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def fedibird_capabilities
capabilities << :enable_wide_emoji_reaction
end
capabilities << :kmyblue_visibility_public_unlisted if Setting.enable_public_unlisted_visibility
capabilities << :timeline_no_local unless Setting.enable_local_timeline

capabilities
end
Expand Down Expand Up @@ -58,6 +59,7 @@ def capabilities_for_nodeinfo
capabilities << :emoji_reaction
capabilities << :enable_wide_emoji_reaction
end
capabilities << :timeline_no_local unless Setting.enable_local_timeline

capabilities
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/form/admin_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Form::AdminSettings
check_lts_version_only
enable_public_unlisted_visibility
unlocked_friend
enable_local_timeline
).freeze

INTEGER_KEYS = %i(
Expand Down Expand Up @@ -81,6 +82,7 @@ class Form::AdminSettings
enable_public_unlisted_visibility
unlocked_friend
stranger_mention_from_local_ng
enable_local_timeline
).freeze

UPLOAD_KEYS = %i(
Expand Down
2 changes: 2 additions & 0 deletions app/models/public_feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def initialize(account, options = {})
# @param [Integer] min_id
# @return [Array<Status>]
def get(limit, max_id = nil, since_id = nil, min_id = nil)
return [] if local_only? && !Setting.enable_local_timeline

scope = public_scope

scope.merge!(without_replies_scope) unless with_replies?
Expand Down
2 changes: 2 additions & 0 deletions app/models/tag_feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def initialize(tag, account, options = {})
# @param [Integer] min_id
# @return [Array<Status>]
def get(limit, max_id = nil, since_id = nil, min_id = nil)
return [] if local_only? && !Setting.enable_local_timeline

scope = public_search_scope

scope.merge!(tagged_with_any_scope)
Expand Down
6 changes: 5 additions & 1 deletion app/services/delivery_antenna_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def delivery!
return if must_dtl_tag && !DTL_ENABLED

tag_ids = @status.tags.pluck(:id)
domain = @account.domain || Rails.configuration.x.local_domain
domain = @account.domain
domain ||= Rails.configuration.x.local_domain if Setting.enable_local_timeline
follower_ids = @status.unlisted_visibility? ? @status.account.followers.pluck(:id) : []

antennas = Antenna.availables
Expand Down Expand Up @@ -77,6 +78,8 @@ def delivery!
end

def delivery_stl!
return unless Setting.enable_local_timeline

antennas = Antenna.available_stls
antennas = antennas.where(account_id: Account.without_suspended.joins(:user).select('accounts.id').where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago))

Expand All @@ -101,6 +104,7 @@ def delivery_ltl!
return if %i(public public_unlisted login).exclude?(@status.visibility.to_sym)
return unless @account.local?
return if @status.reblog?
return unless Setting.enable_local_timeline

antennas = Antenna.available_ltls
antennas = antennas.where(account_id: Account.without_suspended.joins(:user).select('accounts.id').where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago))
Expand Down
14 changes: 8 additions & 6 deletions app/services/fan_out_on_write_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ def fan_out_to_local_recipients!
deliver_to_all_followers!
deliver_to_lists!
deliver_to_antennas! if !@account.dissubscribable || (@status.dtl? && DTL_ENABLED && @account.user&.setting_dtl_force_subscribable && @status.tags.exists?(name: DTL_TAG))
deliver_to_stl_antennas!
deliver_to_ltl_antennas!
deliver_to_stl_antennas! if Setting.enable_local_timeline
deliver_to_ltl_antennas! if Setting.enable_local_timeline
when :limited
deliver_to_lists_mentioned_accounts_only!
deliver_to_antennas! unless @account.dissubscribable
deliver_to_stl_antennas!
deliver_to_stl_antennas! if Setting.enable_local_timeline
deliver_to_mentioned_followers!
else
deliver_to_mentioned_followers!
Expand Down Expand Up @@ -152,19 +152,21 @@ def deliver_to_mentioned_followers!
def broadcast_to_hashtag_streams!
@status.tags.map(&:name).each do |hashtag|
redis.publish("timeline:hashtag:#{hashtag.mb_chars.downcase}", anonymous_payload)
redis.publish("timeline:hashtag:#{hashtag.mb_chars.downcase}:local", anonymous_payload) if @status.local?
redis.publish("timeline:hashtag:#{hashtag.mb_chars.downcase}:local", anonymous_payload) if @status.local? && Setting.enable_local_timeline
end
end

def broadcast_to_public_streams!
return if @status.reply? && @status.in_reply_to_account_id != @account.id

redis.publish('timeline:public', anonymous_payload)
redis.publish(@status.local? ? 'timeline:public:local' : 'timeline:public:remote', anonymous_payload)
redis.publish('timeline:public:remote', anonymous_payload) unless @status.local?
redis.publish('timeline:public:local', anonymous_payload) if @status.local? && Setting.enable_local_timeline

if @status.with_media?
redis.publish('timeline:public:media', anonymous_payload)
redis.publish(@status.local? ? 'timeline:public:local:media' : 'timeline:public:remote:media', anonymous_payload)
redis.publish('timeline:public:remote:media', anonymous_payload) unless @status.local?
redis.publish('timeline:public:local:media', anonymous_payload) if @status.local? && Setting.enable_local_timeline
end
end

Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ defaults: &defaults
enable_public_unlisted_visibility: true
unlocked_friend: false
stranger_mention_from_local_ng: true
enable_local_timeline: true

development:
<<: *defaults
Expand Down
20 changes: 20 additions & 0 deletions spec/models/public_feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@
it 'includes public_unlisted statuses' do
expect(subject).to include(public_unlisted_status.id)
end

context 'when local timeline is disabled' do
before do
Form::AdminSettings.new(enable_local_timeline: '0').save
end

it 'does not include all statuses' do
expect(subject).to eq []
end
end
end

context 'with a viewer' do
Expand All @@ -150,6 +160,16 @@
expect(subject).to include(public_unlisted_status.id)
end
end

context 'when local timeline is disabled' do
before do
Form::AdminSettings.new(enable_local_timeline: '0').save
end

it 'does not include all statuses' do
expect(subject).to eq []
end
end
end

context 'with a remote_only option set' do
Expand Down
6 changes: 6 additions & 0 deletions spec/models/tag_feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
expect(results).to_not include status_tagged_with_cats
end

it 'can restrict to local but local timeline is disabled' do
Form::AdminSettings.new(enable_local_timeline: '0').save
results = described_class.new(tag_cats, nil, any: [tag_dogs.name], local: true).get(20)
expect(results).to_not include status_tagged_with_cats
end

it 'allows replies to be included' do
original = Fabricate(:status)
status = Fabricate(:status, tags: [tag_cats], in_reply_to_id: original.id)
Expand Down
27 changes: 27 additions & 0 deletions spec/services/delivery_antenna_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
RSpec.describe DeliveryAntennaService, type: :service do
subject { described_class.new }

let(:ltl_enabled) { true }

let(:last_active_at) { Time.now.utc }
let(:last_active_at_tom) { Time.now.utc }
let(:visibility) { :public }
Expand Down Expand Up @@ -36,6 +38,8 @@
bob.follow!(alice)
alice.block!(ohagi)

Form::AdminSettings.new(enable_local_timeline: '0').save unless ltl_enabled

allow(redis).to receive(:publish)

subject.call(status, false, mode: mode)
Expand Down Expand Up @@ -124,6 +128,29 @@ def list(owner)
end
end

context 'with local domain' do
let(:domain) { nil }
let!(:antenna) { antenna_with_domain(bob, 'cb6e6126.ngrok.io') }
let!(:empty_antenna) { antenna_with_domain(tom, 'ohagi.example.com') }

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

context 'when local timeline is disabled' do
let(:ltl_enabled) { false }

it 'not detecting antenna' do
expect(antenna_feed_of(antenna)).to_not include status.id
expect(antenna_feed_of(empty_antenna)).to_not include status.id
end
end
end

context 'with tag' do
let!(:antenna) { antenna_with_tag(bob, 'hoge') }
let!(:empty_antenna) { antenna_with_tag(tom, 'hog') }
Expand Down
Loading

0 comments on commit f889926

Please sign in to comment.