* Add: `conversations`テーブルに`ancestor_status`プロパティ * Fix test * Fix test more * Add: `limited_visibility`に`Reply`を追加、`context`のURI * Add: 外部からの`context`受信処理 * Fix test * Add: 公開範囲「返信」 * Fix test * Fix: 返信に返信以外の公開範囲を設定できない問題 * Add: ローカル投稿時にメンション追加・他サーバーへの転送 * Fix test * Fix test * Test: ローカルスレッドへの返信投稿の転送 * Test: 未知のアカウントからのメンション * Add: 編集・削除の連合に対応 * Remove: 重複テスト * Fix: 改善 * Add: 編集削除の転送処理・返信なのにsilentなメンションでの通知 * Fix: リプライが第三者に届かない問題 * Add: `always_sign_unsafe` * Add: Subject * Remove space * Fix: 他人のスレッドの送信先一覧を非表示 * Fix: おかしいコード
This commit is contained in:
parent
a52a8ce214
commit
a88349af55
42 changed files with 1115 additions and 77 deletions
|
@ -16,12 +16,22 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
let(:conversation) do
|
||||
{
|
||||
id: 'http://example.com/conversation',
|
||||
type: 'Group',
|
||||
inbox: 'http://example.com/actor/inbox',
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
before do
|
||||
sender.update(uri: ActivityPub::TagManager.instance.uri_for(sender))
|
||||
|
||||
stub_request(:get, 'http://example.com/attachment.png').to_return(request_fixture('avatar.txt'))
|
||||
stub_request(:get, 'http://example.com/emoji.png').to_return(body: attachment_fixture('emojo.png'))
|
||||
stub_request(:get, 'http://example.com/emojib.png').to_return(body: attachment_fixture('emojo.png'), headers: { 'Content-Type' => 'application/octet-stream' })
|
||||
stub_request(:get, 'http://example.com/conversation').to_return(body: Oj.dump(conversation))
|
||||
stub_request(:get, 'http://example.com/invalid-conversation').to_return(status: 404)
|
||||
end
|
||||
|
||||
describe 'processing posts received out of order', :sidekiq_fake do
|
||||
|
@ -122,11 +132,12 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
describe '#perform' do
|
||||
context 'when fetching' do
|
||||
subject { described_class.new(json, sender) }
|
||||
subject { delivered_to_account_id ? described_class.new(json, sender, delivered_to_account_id: delivered_to_account_id) : described_class.new(json, sender) }
|
||||
|
||||
let(:sender_software) { 'mastodon' }
|
||||
let(:custom_before) { false }
|
||||
let(:active_friend) { false }
|
||||
let(:delivered_to_account_id) { nil }
|
||||
|
||||
before do
|
||||
Fabricate(:instance_info, domain: 'example.com', software: sender_software)
|
||||
|
@ -932,6 +943,259 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with a context' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
context: 'http://example.com/conversation',
|
||||
}
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.conversation).to_not be_nil
|
||||
expect(status.conversation.uri).to eq 'http://example.com/conversation'
|
||||
expect(status.conversation.inbox_url).to eq 'http://example.com/actor/inbox'
|
||||
end
|
||||
|
||||
context 'when existing' do
|
||||
let(:custom_before) { true }
|
||||
let!(:existing) { Fabricate(:conversation, uri: 'http://example.com/conversation', inbox_url: 'http://example.com/actor/invalid') }
|
||||
|
||||
before do
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.conversation).to_not be_nil
|
||||
expect(status.conversation.id).to eq existing.id
|
||||
expect(status.conversation.inbox_url).to eq 'http://example.com/actor/inbox'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an invalid context' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
context: 'http://example.com/invalid-conversation',
|
||||
}
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.text).to eq 'Lorem ipsum'
|
||||
expect(status.conversation).to_not be_nil
|
||||
expect(status.conversation.uri).to eq 'http://example.com/invalid-conversation'
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a local context' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
context: "https://cb6e6126.ngrok.io/contexts/#{existing.id}",
|
||||
}
|
||||
end
|
||||
|
||||
let(:existing) { Fabricate(:conversation, id: 3500) }
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.conversation).to_not be_nil
|
||||
expect(status.conversation.uri).to be_nil
|
||||
expect(status.conversation.id).to eq existing.id
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a context as a reply' do
|
||||
let(:custom_before) { true }
|
||||
let(:custom_before_sub) { false }
|
||||
let(:ancestor_account) { Fabricate(:account, domain: 'or.example.com', inbox_url: 'http://or.example.com/actor/inbox') }
|
||||
let(:mentioned_account) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/bob', inbox_url: 'http://example.com/bob/inbox', shared_inbox_url: 'http://exmaple.com/inbox') }
|
||||
let(:local_mentioned_account) { Fabricate(:account, domain: nil) }
|
||||
let(:original_status) { Fabricate(:status, conversation: conversation, account: ancestor_account) }
|
||||
let!(:conversation) { Fabricate(:conversation) }
|
||||
let(:recipient) { Fabricate(:account) }
|
||||
let(:delivered_to_account_id) { recipient.id }
|
||||
|
||||
let(:json) do
|
||||
{
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#foo'].join,
|
||||
type: 'Create',
|
||||
actor: ActivityPub::TagManager.instance.uri_for(sender),
|
||||
object: object_json,
|
||||
signature: 'dummy',
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
context: ActivityPub::TagManager.instance.uri_for(conversation),
|
||||
inReplyTo: ActivityPub::TagManager.instance.uri_for(original_status),
|
||||
}
|
||||
end
|
||||
|
||||
before do
|
||||
original_status.mentions << Fabricate(:mention, account: mentioned_account, silent: true)
|
||||
original_status.mentions << Fabricate(:mention, account: local_mentioned_account, silent: true)
|
||||
original_status.save!
|
||||
conversation.update(ancestor_status: original_status)
|
||||
|
||||
stub_request(:post, 'http://or.example.com/actor/inbox').to_return(status: 200)
|
||||
stub_request(:post, 'http://example.com/bob/inbox').to_return(status: 200)
|
||||
|
||||
subject.perform unless custom_before_sub
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.conversation_id).to eq conversation.id
|
||||
expect(status.thread.id).to eq original_status.id
|
||||
expect(status.mentions.map(&:account_id)).to contain_exactly(recipient.id, ancestor_account.id, mentioned_account.id, local_mentioned_account.id)
|
||||
end
|
||||
|
||||
it 'forwards to observers' do
|
||||
expect(a_request(:post, 'http://or.example.com/actor/inbox')).to have_been_made.once
|
||||
expect(a_request(:post, 'http://example.com/bob/inbox')).to have_been_made.once
|
||||
end
|
||||
|
||||
context 'when new mention is added' do
|
||||
let(:custom_before_sub) { true }
|
||||
|
||||
let(:new_mentioned_account) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/alice', inbox_url: 'http://example.com/alice/inbox', shared_inbox_url: 'http://exmaple.com/inbox') }
|
||||
let(:new_local_mentioned_account) { Fabricate(:account, domain: nil) }
|
||||
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
context: ActivityPub::TagManager.instance.uri_for(conversation),
|
||||
inReplyTo: ActivityPub::TagManager.instance.uri_for(original_status),
|
||||
tag: [
|
||||
{
|
||||
type: 'Mention',
|
||||
href: ActivityPub::TagManager.instance.uri_for(new_mentioned_account),
|
||||
},
|
||||
{
|
||||
type: 'Mention',
|
||||
href: ActivityPub::TagManager.instance.uri_for(new_local_mentioned_account),
|
||||
},
|
||||
],
|
||||
}
|
||||
end
|
||||
|
||||
before do
|
||||
stub_request(:post, 'http://example.com/alice/inbox').to_return(status: 200)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.mentions.map(&:account_id)).to contain_exactly(recipient.id, ancestor_account.id, mentioned_account.id, local_mentioned_account.id, new_mentioned_account.id, new_local_mentioned_account.id)
|
||||
end
|
||||
|
||||
it 'forwards to observers' do
|
||||
expect(a_request(:post, 'http://or.example.com/actor/inbox')).to have_been_made.once
|
||||
expect(a_request(:post, 'http://example.com/bob/inbox')).to have_been_made.once
|
||||
expect(a_request(:post, 'http://example.com/alice/inbox')).to have_been_made.once
|
||||
end
|
||||
end
|
||||
|
||||
context 'when unknown mentioned account' do
|
||||
let(:custom_before_sub) { true }
|
||||
|
||||
let(:actor_json) do
|
||||
{
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: 'https://foo.test',
|
||||
type: 'Person',
|
||||
preferredUsername: 'actor',
|
||||
name: 'Tomas Cat',
|
||||
inbox: 'https://foo.test/inbox',
|
||||
}.with_indifferent_access
|
||||
end
|
||||
let!(:webfinger) { { subject: 'acct:actor@foo.test', links: [{ rel: 'self', href: 'https://foo.test' }] } }
|
||||
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
context: ActivityPub::TagManager.instance.uri_for(conversation),
|
||||
inReplyTo: ActivityPub::TagManager.instance.uri_for(original_status),
|
||||
tag: [
|
||||
{
|
||||
type: 'Mention',
|
||||
href: 'https://foo.test',
|
||||
},
|
||||
],
|
||||
}
|
||||
end
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://foo.test').to_return(status: 200, body: Oj.dump(actor_json))
|
||||
stub_request(:get, 'https://foo.test/.well-known/webfinger?resource=acct:actor@foo.test').to_return(status: 200, body: Oj.dump(webfinger))
|
||||
stub_request(:post, 'https://foo.test/inbox').to_return(status: 200)
|
||||
stub_request(:get, 'https://foo.test/.well-known/nodeinfo').to_return(status: 200)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.mentioned_accounts.map(&:uri)).to include 'https://foo.test'
|
||||
end
|
||||
|
||||
it 'forwards to observers' do
|
||||
expect(a_request(:post, 'https://foo.test/inbox')).to have_been_made.once
|
||||
end
|
||||
end
|
||||
|
||||
context 'when remote conversation' do
|
||||
let(:conversation) { Fabricate(:conversation, uri: 'http://example.com/conversation', inbox_url: 'http://example.com/actor/inbox') }
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.conversation_id).to eq conversation.id
|
||||
expect(status.thread.id).to eq original_status.id
|
||||
expect(status.mentions.map(&:account_id)).to contain_exactly(recipient.id)
|
||||
end
|
||||
|
||||
it 'do not forward to observers' do
|
||||
expect(a_request(:post, 'http://or.example.com/actor/inbox')).to_not have_been_made
|
||||
expect(a_request(:post, 'http://example.com/bob/inbox')).to_not have_been_made
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with media attachments' do
|
||||
let(:object_json) do
|
||||
{
|
||||
|
|
|
@ -74,6 +74,27 @@ RSpec.describe ActivityPub::Activity::Delete do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when the status is limited post and has conversation' do
|
||||
subject { described_class.new(json, sender) }
|
||||
|
||||
let(:conversation) { Fabricate(:conversation, ancestor_status: status) }
|
||||
|
||||
before do
|
||||
status.update(conversation: conversation, visibility: :limited)
|
||||
status.mentions << Fabricate(:mention, silent: true, account: Fabricate(:account, protocol: :activitypub, domain: 'example.com', inbox_url: 'https://example.com/actor/inbox', shared_inbox_url: 'https://example.com/inbox'))
|
||||
status.save
|
||||
stub_request(:post, 'https://example.com/inbox').to_return(status: 200)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'forwards to parent status holder' do
|
||||
expect(a_request(:post, 'https://example.com/inbox').with(body: hash_including({
|
||||
type: 'Delete',
|
||||
signature: 'foo',
|
||||
}))).to have_been_made.once
|
||||
end
|
||||
end
|
||||
|
||||
context 'when given a friend server' do
|
||||
subject { described_class.new(json, sender) }
|
||||
|
||||
|
|
|
@ -115,5 +115,39 @@ RSpec.describe ActivityPub::Activity::Update do
|
|||
expect(status.edited_at).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the status is limited post and has conversation' do
|
||||
let(:status) { Fabricate(:status, visibility: :limited, account: sender, uri: 'https://example.com/note', text: 'Ohagi is koshian') }
|
||||
let(:conversation) { Fabricate(:conversation, ancestor_status: status) }
|
||||
let(:json) do
|
||||
{
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: 'foo',
|
||||
type: 'Update',
|
||||
actor: sender.uri,
|
||||
signature: 'foo',
|
||||
object: {
|
||||
type: 'Note',
|
||||
id: status.uri,
|
||||
content: 'Ohagi is tsubuan',
|
||||
},
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
before do
|
||||
status.update(conversation: conversation, visibility: :limited)
|
||||
status.mentions << Fabricate(:mention, silent: true, account: Fabricate(:account, protocol: :activitypub, domain: 'example.com', inbox_url: 'https://example.com/actor/inbox', shared_inbox_url: 'https://example.com/inbox'))
|
||||
status.save
|
||||
stub_request(:post, 'https://example.com/inbox').to_return(status: 200)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'forwards to parent status holder' do
|
||||
expect(a_request(:post, 'https://example.com/inbox').with(body: hash_including({
|
||||
type: 'Update',
|
||||
signature: 'foo',
|
||||
}))).to have_been_made.once
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -593,6 +593,16 @@ RSpec.describe Status do
|
|||
expect(described_class.create(account: alice, text: 'First').conversation_id).to_not be_nil
|
||||
end
|
||||
|
||||
it 'creates new owned-conversation for stand-alone status' do
|
||||
expect(described_class.create(account: alice, text: 'First').owned_conversation.id).to_not be_nil
|
||||
end
|
||||
|
||||
it 'creates new owned-conversation and linked for stand-alone status' do
|
||||
status = described_class.create(account: alice, text: 'First')
|
||||
expect(status.owned_conversation.ancestor_status_id).to eq status.id
|
||||
expect(status.conversation.ancestor_status_id).to eq status.id
|
||||
end
|
||||
|
||||
it 'keeps conversation of parent node' do
|
||||
parent = Fabricate(:status, text: 'First')
|
||||
expect(described_class.create(account: alice, thread: parent, text: 'Response').conversation_id).to eq parent.conversation_id
|
||||
|
|
|
@ -115,6 +115,58 @@ RSpec.describe StatusPolicy, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with the permission of show_mentioned_users?' do
|
||||
permissions :show_mentioned_users? do
|
||||
it 'grants access when public and account is viewer' do
|
||||
status.visibility = :public
|
||||
|
||||
expect(subject).to permit(status.account, status)
|
||||
end
|
||||
|
||||
it 'grants access when public and account is not viewer' do
|
||||
status.visibility = :public
|
||||
|
||||
expect(subject).to_not permit(bob, status)
|
||||
end
|
||||
|
||||
it 'grants access when limited and no conversation ancestor_status and account is viewer' do
|
||||
status.visibility = :limited
|
||||
status.conversation = Fabricate(:conversation)
|
||||
|
||||
expect(subject).to permit(status.account, status)
|
||||
end
|
||||
|
||||
it 'grants access when limited and my conversation and account is viewer' do
|
||||
status.visibility = :limited
|
||||
status.conversation = Fabricate(:conversation, ancestor_status: status)
|
||||
|
||||
expect(subject).to permit(status.account, status)
|
||||
end
|
||||
|
||||
it 'grants access when limited and another conversation and account is viewer' do
|
||||
status.visibility = :limited
|
||||
status.conversation = Fabricate(:conversation, ancestor_status: Fabricate(:status, account: bob))
|
||||
|
||||
expect(subject).to_not permit(status.account, status)
|
||||
end
|
||||
|
||||
it 'grants access when limited and viewer is mentioned' do
|
||||
status.visibility = :limited
|
||||
status.mentions = [Fabricate(:mention, account: bob)]
|
||||
|
||||
expect(subject).to_not permit(bob, status)
|
||||
end
|
||||
|
||||
it 'grants access when limited and non-owner viewer is mentioned and mentions are loaded' do
|
||||
status.visibility = :limited
|
||||
status.mentions = [Fabricate(:mention, account: bob)]
|
||||
status.mentions.load
|
||||
|
||||
expect(subject).to_not permit(bob, status)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with the permission of reblog?' do
|
||||
permissions :reblog? do
|
||||
it 'denies access when private' do
|
||||
|
|
|
@ -683,6 +683,84 @@ RSpec.describe FanOutOnWriteService, type: :service do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when status has a conversation' do
|
||||
let(:conversation) { Fabricate(:conversation) }
|
||||
let(:status) { Fabricate(:status, account: alice, visibility: visibility, thread: parent_status, conversation: conversation) }
|
||||
let(:parent_status) { Fabricate(:status, account: bob, visibility: visibility, conversation: conversation) }
|
||||
let(:zilu) { Fabricate(:user, current_sign_in_at: last_active_at).account }
|
||||
let(:custom_before) { true }
|
||||
|
||||
before do
|
||||
zilu.follow!(alice)
|
||||
zilu.follow!(bob)
|
||||
Fabricate(:status, account: tom, visibility: visibility, conversation: conversation)
|
||||
Fabricate(:status, account: ohagi, visibility: visibility, conversation: conversation)
|
||||
status.mentions << Fabricate(:mention, account: bob, silent: true)
|
||||
status.mentions << Fabricate(:mention, account: ohagi, silent: true)
|
||||
status.mentions << Fabricate(:mention, account: zilu, silent: true)
|
||||
status.mentions << Fabricate(:mention, account: tom, silent: false)
|
||||
status.save
|
||||
subject.call(status)
|
||||
end
|
||||
|
||||
context 'when public visibility' do
|
||||
it 'does not create notification' do
|
||||
notification = Notification.find_by(account: bob, type: 'mention')
|
||||
|
||||
expect(notification).to be_nil
|
||||
end
|
||||
|
||||
it 'creates notification for active mention' do
|
||||
notification = Notification.find_by(account: tom, type: 'mention')
|
||||
|
||||
expect(notification).to_not be_nil
|
||||
expect(notification.mention.status_id).to eq status.id
|
||||
end
|
||||
|
||||
it 'inserts home feed for reply' do
|
||||
expect(home_feed_of(bob)).to include status.id
|
||||
end
|
||||
|
||||
it 'inserts home feed for non-replied but mentioned and following replied account' do
|
||||
expect(home_feed_of(zilu)).to include status.id
|
||||
end
|
||||
|
||||
it 'does not insert home feed for non-replied, non-following replied account but mentioned' do
|
||||
expect(home_feed_of(tom)).to_not include status.id
|
||||
end
|
||||
end
|
||||
|
||||
context 'when limited visibility' do
|
||||
let(:visibility) { :limited }
|
||||
|
||||
it 'creates notification' do
|
||||
notification = Notification.find_by(account: bob, type: 'mention')
|
||||
|
||||
expect(notification).to_not be_nil
|
||||
expect(notification.mention.status_id).to eq status.id
|
||||
end
|
||||
|
||||
it 'creates notification for other conversation account' do
|
||||
notification = Notification.find_by(account: ohagi, type: 'mention')
|
||||
|
||||
expect(notification).to_not be_nil
|
||||
expect(notification.mention.status_id).to eq status.id
|
||||
end
|
||||
|
||||
it 'inserts home feed for reply' do
|
||||
expect(home_feed_of(bob)).to include status.id
|
||||
end
|
||||
|
||||
it 'inserts home feed for non-replied but mentioned and following replied account' do
|
||||
expect(home_feed_of(zilu)).to include status.id
|
||||
end
|
||||
|
||||
it 'does not insert home feed for non-replied, non-following replied account but mentioned' do
|
||||
expect(home_feed_of(tom)).to_not include status.id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when updated status is already boosted or quoted' do
|
||||
let(:custom_before) { true }
|
||||
|
||||
|
|
|
@ -263,7 +263,7 @@ RSpec.describe PostStatusService, type: :service do
|
|||
expect(status.limited_scope).to eq 'circle'
|
||||
end
|
||||
|
||||
it 'limited visibility and empty circle' do
|
||||
it 'limited visibility without circle' do
|
||||
account = Fabricate(:account)
|
||||
text = 'This is an English text.'
|
||||
|
||||
|
@ -295,6 +295,158 @@ RSpec.describe PostStatusService, type: :service do
|
|||
expect(status.mentioned_accounts.count).to eq 1
|
||||
end
|
||||
|
||||
describe 'create a new response status to limited post' do
|
||||
it 'when reply visibility' do
|
||||
in_reply_to_status = Fabricate(:status, visibility: :limited)
|
||||
account = Fabricate(:account)
|
||||
text = 'test status update'
|
||||
|
||||
status = subject.call(account, text: text, thread: in_reply_to_status, visibility: 'reply')
|
||||
|
||||
expect(status).to be_persisted
|
||||
expect(status.thread).to eq in_reply_to_status
|
||||
expect(status.visibility).to eq 'limited'
|
||||
expect(status.limited_scope).to eq 'reply'
|
||||
end
|
||||
|
||||
it 'when limited visibility' do
|
||||
in_reply_to_status = Fabricate(:status, visibility: :limited)
|
||||
account = Fabricate(:account)
|
||||
text = 'test status update'
|
||||
|
||||
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
|
||||
expect(status.visibility).to eq 'limited'
|
||||
expect(status.limited_scope).to eq 'reply'
|
||||
end
|
||||
|
||||
it 'when circle visibility' do
|
||||
in_reply_to_status = Fabricate(:status, visibility: :limited)
|
||||
account = Fabricate(:account)
|
||||
text = 'test status update'
|
||||
|
||||
circle = Fabricate(:circle, account: account)
|
||||
circle_account = Fabricate(:account)
|
||||
circle_account.follow!(account)
|
||||
circle.accounts << circle_account
|
||||
circle.save!
|
||||
|
||||
status = subject.call(account, text: text, thread: in_reply_to_status, visibility: 'circle', circle_id: circle.id)
|
||||
|
||||
expect(status).to be_persisted
|
||||
expect(status.thread).to eq in_reply_to_status
|
||||
expect(status.visibility).to eq 'limited'
|
||||
expect(status.limited_scope).to eq 'circle'
|
||||
expect(status.mentioned_accounts.pluck(:id)).to eq [circle_account.id]
|
||||
end
|
||||
|
||||
it 'when public visibility' do
|
||||
in_reply_to_status = Fabricate(:status, visibility: :limited)
|
||||
account = Fabricate(:account)
|
||||
text = 'test status update'
|
||||
|
||||
status = subject.call(account, text: text, thread: in_reply_to_status, visibility: :public)
|
||||
|
||||
expect(status).to be_persisted
|
||||
expect(status.thread).to eq in_reply_to_status
|
||||
expect(status.visibility).to eq 'public'
|
||||
end
|
||||
|
||||
it 'when direct visibility' do
|
||||
in_reply_to_status = Fabricate(:status, visibility: :limited)
|
||||
account = Fabricate(:account)
|
||||
text = 'test status update'
|
||||
|
||||
status = subject.call(account, text: text, thread: in_reply_to_status, visibility: :direct)
|
||||
|
||||
expect(status).to be_persisted
|
||||
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
|
||||
account = Fabricate(:account)
|
||||
mentioned_account = Fabricate(:account, username: 'alice')
|
||||
|
|
|
@ -8,12 +8,14 @@ RSpec.describe RemoveStatusService, type: :service do
|
|||
let!(:alice) { Fabricate(:account) }
|
||||
let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
|
||||
let!(:jeff) { Fabricate(:account) }
|
||||
let!(:hank) { Fabricate(:account, username: 'hank', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
|
||||
let!(:bill) { Fabricate(:account, username: 'bill', protocol: :activitypub, domain: 'example2.com', inbox_url: 'http://example2.com/inbox') }
|
||||
let!(:hank) { Fabricate(:account, username: 'hank', protocol: :activitypub, domain: 'example.com', shared_inbox_url: 'http://example.com/inbox', inbox_url: 'http://example.com/hank/inbox') }
|
||||
let!(:bill) { Fabricate(:account, username: 'bill', protocol: :activitypub, domain: 'example2.com', shared_inbox_url: 'http://example2.com/inbox', inbox_url: 'http://example2.com/bill/inbox') }
|
||||
|
||||
before do
|
||||
stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
|
||||
stub_request(:post, 'http://example.com/hank/inbox').to_return(status: 200)
|
||||
stub_request(:post, 'http://example2.com/inbox').to_return(status: 200)
|
||||
stub_request(:post, 'http://example2.com/bill/inbox').to_return(status: 200)
|
||||
|
||||
jeff.follow!(alice)
|
||||
hank.follow!(alice)
|
||||
|
@ -72,6 +74,57 @@ RSpec.describe RemoveStatusService, type: :service do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when removed status is limited' do
|
||||
let(:status) { PostStatusService.new.call(alice, visibility: 'mutual', text: 'limited post') }
|
||||
|
||||
before do
|
||||
status.mentions << Fabricate(:mention, account: hank, silent: true)
|
||||
end
|
||||
|
||||
it 'sends Delete activity to followers' do
|
||||
subject.call(status)
|
||||
expect(a_request(:post, 'http://example.com/inbox').with(
|
||||
body: hash_including({
|
||||
'type' => 'Delete',
|
||||
'object' => {
|
||||
'type' => 'Tombstone',
|
||||
'id' => ActivityPub::TagManager.instance.uri_for(status),
|
||||
'atomUri' => OStatus::TagManager.instance.uri_for(status),
|
||||
},
|
||||
})
|
||||
)).to have_been_made.once
|
||||
end
|
||||
end
|
||||
|
||||
context 'when removed status is limited and remote conversation' do
|
||||
let(:status) { PostStatusService.new.call(alice, visibility: 'mutual', text: 'limited post') }
|
||||
|
||||
before do
|
||||
status.conversation.update(uri: 'http://example2.com/conversation', inbox_url: 'http://example2.com/bill/inbox')
|
||||
status.mentions << Fabricate(:mention, account: hank, silent: true)
|
||||
end
|
||||
|
||||
it 'sends Delete activity to conversation' do
|
||||
subject.call(status)
|
||||
expect(a_request(:post, 'http://example2.com/bill/inbox').with(
|
||||
body: hash_including({
|
||||
'type' => 'Delete',
|
||||
'object' => {
|
||||
'type' => 'Tombstone',
|
||||
'id' => ActivityPub::TagManager.instance.uri_for(status),
|
||||
'atomUri' => OStatus::TagManager.instance.uri_for(status),
|
||||
},
|
||||
})
|
||||
)).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'do not send Delete activity to followers' do
|
||||
subject.call(status)
|
||||
expect(a_request(:post, 'http://example.com/hank/inbox')).to_not have_been_made
|
||||
expect(a_request(:post, 'http://example.com/inbox')).to_not have_been_made
|
||||
end
|
||||
end
|
||||
|
||||
context 'when removed status is a private self-reblog' do
|
||||
let!(:original_status) { Fabricate(:status, account: alice, text: 'Hello ThisIsASecret', visibility: :private) }
|
||||
let!(:status) { ReblogService.new.call(alice, original_status) }
|
||||
|
|
|
@ -63,6 +63,22 @@ describe ActivityPub::DistributionWorker do
|
|||
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 limited status for no-follower but non-mentioned follower' do
|
||||
let(:no_follower) { Fabricate(:account, domain: 'example.com', inbox_url: 'http://example.com/no_follower/inbox', shared_inbox_url: 'http://example.com') }
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ describe ActivityPub::StatusUpdateDistributionWorker do
|
|||
subject { described_class.new }
|
||||
|
||||
let(:status) { Fabricate(:status, text: 'foo') }
|
||||
let(:follower) { Fabricate(:account, protocol: :activitypub, inbox_url: 'http://example.com', domain: 'example.com') }
|
||||
let(:follower) { Fabricate(:account, protocol: :activitypub, shared_inbox_url: 'http://example.com', inbox_url: 'http://example.com/follower/inbox', domain: 'example.com') }
|
||||
|
||||
describe '#perform' do
|
||||
before do
|
||||
|
@ -31,6 +31,18 @@ describe ActivityPub::StatusUpdateDistributionWorker do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with unlisted status' do
|
||||
before do
|
||||
status.update(visibility: :unlisted)
|
||||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'http://example.com', anything]]) do
|
||||
subject.perform(status.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with private status' do
|
||||
before do
|
||||
status.update(visibility: :private)
|
||||
|
@ -42,5 +54,35 @@ describe ActivityPub::StatusUpdateDistributionWorker do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with limited status' do
|
||||
before do
|
||||
status.update(visibility: :limited)
|
||||
status.capability_tokens.create!
|
||||
status.mentions.create!(account: follower, silent: true)
|
||||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'http://example.com', anything]]) do
|
||||
subject.perform(status.id)
|
||||
end
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue