Skip to content

Commit

Permalink
Revert "Add: ローカル投稿時にメンション追加・他サーバーへの転送"
Browse files Browse the repository at this point in the history
This reverts commit d3182a7.
  • Loading branch information
kmycode committed Nov 20, 2023
1 parent d3182a7 commit a058b4a
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 197 deletions.
11 changes: 0 additions & 11 deletions app/lib/activitypub/activity/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def process_status
process_references!
distribute
forward_for_reply
forward_for_conversation if @status.limited_visibility?
join_group!
end

Expand Down Expand Up @@ -512,16 +511,6 @@ def forward_for_reply
ActivityPub::RawDistributionWorker.perform_async(Oj.dump(@json), replied_to_status.account_id, [@account.preferred_inbox_url])
end

def forward_for_conversation
return unless @status.conversation.present? && @status.conversation.local?

ProcessConversionService.new.call(@status)

return if @json['signature'].blank?

ActivityPub::ForwardConversationWorker.perform_async(Oj.dump(@json), @status.id)
end

def increment_voters_count!
poll = replied_to_status.preloadable_poll

Expand Down
2 changes: 1 addition & 1 deletion app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def set_conversation

self.reply = !(in_reply_to_id.nil? && thread.nil?) unless reply

if reply? && !thread.nil? && (!limited_visibility? || none_limited? || reply_limited?)
if reply? && !thread.nil?
self.in_reply_to_account_id = carried_over_reply_to_account_id
self.conversation_id = thread.conversation_id if conversation_id.nil?
elsif conversation_id.nil?
Expand Down
5 changes: 2 additions & 3 deletions app/services/post_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def preprocess_attributes!
@visibility = :limited if %w(mutual circle reply).include?(@options[:visibility])
@visibility = :unlisted if (@visibility == :public || @visibility == :public_unlisted || @visibility == :login) && @account.silenced?
@visibility = :public_unlisted if @visibility == :public && !@options[:force_visibility] && !@options[:application]&.superapp && @account.user&.setting_public_post_to_unlisted && Setting.enable_public_unlisted_visibility
@limited_scope = @options[:visibility]&.to_sym if @visibility == :limited && @options[:visibility] != 'limited'
@limited_scope = @options[:visibility]&.to_sym if @visibility == :limited
@searchability = searchability
@searchability = :private if @account.silenced? && %i(public public_unlisted).include?(@searchability&.to_sym)
@markdown = @options[:markdown] || false
Expand All @@ -87,7 +87,7 @@ def preprocess_attributes!
@reference_ids = (@options[:status_reference_ids] || []).map(&:to_i).filter(&:positive?)
raise ArgumentError if !Setting.enable_public_unlisted_visibility && @visibility == :public_unlisted

if @in_reply_to.present? && ((@options[:visibility] == 'limited' && @options[:circle_id].nil?) || @limited_scope == :reply)
if @in_reply_to.present? && ((@visibility == :limited && @options[:circle_id].nil?) || @limited_scope == :reply)
@visibility = :limited
@limited_scope = :reply
end
Expand Down Expand Up @@ -201,7 +201,6 @@ def postprocess_status!

process_hashtags_service.call(@status)
Trends.tags.register(@status)
ProcessConversionService.new.call(@status) if @status.limited_visibility? && @status.reply_limited?
ProcessReferencesService.call_service(@status, @reference_ids, [])
LinkCrawlWorker.perform_async(@status.id)
DistributionWorker.perform_async(@status.id)
Expand Down
33 changes: 0 additions & 33 deletions app/services/process_conversion_service.rb

This file was deleted.

15 changes: 0 additions & 15 deletions app/workers/activitypub/distribution_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,11 @@ def perform(status_id)
protected

def distribute_limited!
if @status.reply? && @status.conversation.present? && !@status.conversation.local?
distribute_conversation!
else
distribute_limited_mentions!
end
end

def distribute_limited_mentions!
ActivityPub::DeliveryWorker.push_bulk(inboxes_for_limited, limit: 1_000) do |inbox_url|
[payload, @account.id, inbox_url, options]
end
end

def distribute_conversation!
inbox_url = @status.conversation.inbox_url
return if inbox_url.blank?

ActivityPub::DeliveryWorker.perform_async(payload, @account.id, inbox_url, options)
end

def inboxes
@inboxes ||= status_reach_finder.inboxes
end
Expand Down
37 changes: 0 additions & 37 deletions app/workers/activitypub/forward_conversion_worker.rb

This file was deleted.

82 changes: 1 addition & 81 deletions spec/services/post_status_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
account = Fabricate(:account)
text = 'test status update'

status = subject.call(account, text: text, thread: in_reply_to_status, visibility: 'limited')
status = subject.call(account, text: text, thread: in_reply_to_status, visibility: :limited)

expect(status).to be_persisted
expect(status.thread).to eq in_reply_to_status
Expand Down Expand Up @@ -365,86 +365,6 @@
expect(status.thread).to eq in_reply_to_status
expect(status.visibility).to eq 'direct'
end

it 'duplicate replies' do
in_reply_to_status = Fabricate(:status, visibility: :limited)
in_reply_to_status.mentions.create!(account: Fabricate(:account))

status = subject.call(Fabricate(:user).account, text: 'Ohagi is good', thread: in_reply_to_status, visibility: 'reply')

thread_account_ids = [in_reply_to_status.account, in_reply_to_status.mentions.first.account].map(&:id)

expect(status).to be_persisted
expect(status.conversation_id).to eq in_reply_to_status.conversation_id
expect(status.conversation.ancestor_status_id).to eq in_reply_to_status.id
expect(status.mentions.pluck(:account_id)).to match_array thread_account_ids
end

it 'duplicate reply-to-reply' do
ancestor_account = Fabricate(:account, username: 'ancestor', domain: nil)
reply_account = Fabricate(:account)

first_status = Fabricate(:status, account: ancestor_account, visibility: :limited)
in_reply_to_status = subject.call(reply_account, text: 'Ohagi is good, @ancestor', thread: first_status, visibility: 'reply')
status = subject.call(ancestor_account, text: 'Ohagi is good', thread: in_reply_to_status, visibility: 'reply')

thread_account_ids = [ancestor_account, reply_account].map(&:id)

expect(status).to be_persisted
expect(status.conversation_id).to eq in_reply_to_status.conversation_id
expect(status.conversation_id).to eq first_status.conversation_id
expect(status.conversation.ancestor_status_id).to eq first_status.id
expect(status.mentions.pluck(:account_id)).to match_array thread_account_ids
end

it 'duplicate reply-to-third_reply' do
first_status = Fabricate(:status, visibility: :limited)
first_status.mentions.create!(account: Fabricate(:account))

mentioned_account = Fabricate(:account, username: 'ohagi', domain: nil)
mentioned_account2 = Fabricate(:account, username: 'bob', domain: nil)
in_reply_to_status = subject.call(Fabricate(:user).account, text: 'Ohagi is good, @ohagi', thread: first_status, visibility: 'reply')
status = subject.call(Fabricate(:user).account, text: 'Ohagi is good, @bob', thread: in_reply_to_status, visibility: 'reply')

thread_account_ids = [first_status.account, first_status.mentions.first.account, mentioned_account, mentioned_account2, in_reply_to_status.account].map(&:id)

expect(status).to be_persisted
expect(status.conversation_id).to eq in_reply_to_status.conversation_id
expect(status.conversation_id).to eq first_status.conversation_id
expect(status.conversation.ancestor_status_id).to eq first_status.id
expect(status.mentions.pluck(:account_id)).to match_array thread_account_ids
end

it 'do not duplicate replies when limited post' do
in_reply_to_status = Fabricate(:status, visibility: :limited)
in_reply_to_status.mentions.create!(account: Fabricate(:account))

status = subject.call(Fabricate(:user).account, text: 'Ohagi is good', thread: in_reply_to_status, visibility: 'mutual')

[in_reply_to_status.account, in_reply_to_status.mentions.first.account].map(&:id)

expect(status).to be_persisted
expect(status.limited_scope).to eq 'personal'

mentions = status.mentions.pluck(:account_id)
expect(mentions).to_not include in_reply_to_status.account_id
expect(mentions).to_not include in_reply_to_status.mentions.first.account_id
end

it 'do not duplicate replies when not limited post' do
in_reply_to_status = Fabricate(:status, visibility: :limited)
in_reply_to_status.mentions.create!(account: Fabricate(:account))

status = subject.call(Fabricate(:user).account, text: 'Ohagi is good', thread: in_reply_to_status, visibility: 'public')

[in_reply_to_status.account, in_reply_to_status.mentions.first.account].map(&:id)

expect(status).to be_persisted

mentions = status.mentions.pluck(:account_id)
expect(mentions).to_not include in_reply_to_status.account_id
expect(mentions).to_not include in_reply_to_status.mentions.first.account_id
end
end

it 'safeguards mentions' do
Expand Down
16 changes: 0 additions & 16 deletions spec/workers/activitypub/distribution_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,6 @@
end
end

context 'with limited response status' do
before do
allow(ActivityPub::DeliveryWorker).to receive(:perform_async).with(kind_of(String), status.account.id, 'http://example.com/conversation/inbox', anything)
status.update(visibility: :limited, thread: Fabricate(:status))
status.conversation.update(uri: 'https://example.com/conversation', inbox_url: 'http://example.com/conversation/inbox')
status.capability_tokens.create!
status.mentions.create!(account: follower, silent: true)
stub_request(:post, 'http://example.com/conversation/inbox')
end

it 'delivers to followers' do
subject.perform(status.id)
expect(ActivityPub::DeliveryWorker).to have_received(:perform_async)
end
end

context 'with direct status' do
let(:mentioned_account) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://foo.bar/inbox', domain: 'foo.bar') }

Expand Down

0 comments on commit a058b4a

Please sign in to comment.