2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-12 01:13:43 +10:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-07-09 02:01:08 +10:00
|
|
|
RSpec.describe RemoveStatusService, :inline_jobs do
|
2023-06-06 21:58:33 +10:00
|
|
|
subject { described_class.new }
|
2017-06-12 01:13:43 +10:00
|
|
|
|
2022-01-28 10:46:42 +11:00
|
|
|
let!(:alice) { Fabricate(:account) }
|
2021-05-08 03:32:58 +10:00
|
|
|
let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
|
2017-06-12 01:13:43 +10:00
|
|
|
let!(:jeff) { Fabricate(:account) }
|
2017-08-13 08:44:41 +10:00
|
|
|
let!(:hank) { Fabricate(:account, username: 'hank', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
|
2017-08-29 05:38:59 +10:00
|
|
|
let!(:bill) { Fabricate(:account, username: 'bill', protocol: :activitypub, domain: 'example2.com', inbox_url: 'http://example2.com/inbox') }
|
2017-06-12 01:13:43 +10:00
|
|
|
|
|
|
|
before do
|
2023-12-22 01:23:53 +11:00
|
|
|
stub_request(:post, hank.inbox_url).to_return(status: 200)
|
|
|
|
stub_request(:post, bill.inbox_url).to_return(status: 200)
|
2017-06-12 01:13:43 +10:00
|
|
|
|
|
|
|
jeff.follow!(alice)
|
2017-08-13 08:44:41 +10:00
|
|
|
hank.follow!(alice)
|
2017-06-12 01:13:43 +10:00
|
|
|
end
|
|
|
|
|
2022-02-12 00:52:07 +11:00
|
|
|
context 'when removed status is not a reblog' do
|
2024-01-09 20:40:08 +11:00
|
|
|
let!(:media_attachment) { Fabricate(:media_attachment, account: alice) }
|
|
|
|
let!(:status) { PostStatusService.new.call(alice, text: "Hello @#{bob.pretty_acct} ThisIsASecret", media_ids: [media_attachment.id]) }
|
2023-11-09 02:42:30 +11:00
|
|
|
|
2022-02-12 00:52:07 +11:00
|
|
|
before do
|
2023-11-09 02:42:30 +11:00
|
|
|
FavouriteService.new.call(jeff, status)
|
|
|
|
Fabricate(:status, account: bill, reblog: status, uri: 'hoge')
|
2022-02-12 00:52:07 +11:00
|
|
|
end
|
2017-06-12 01:13:43 +10:00
|
|
|
|
2024-10-05 00:11:15 +10:00
|
|
|
it 'removes status from notifications and from author and local follower home feeds, publishes to media timeline, sends delete activities' do
|
2024-01-09 20:40:08 +11:00
|
|
|
allow(redis).to receive(:publish).with(any_args)
|
|
|
|
|
2024-10-05 00:11:15 +10:00
|
|
|
expect { subject.call(status) }
|
|
|
|
.to remove_status_from_notifications
|
2024-01-09 20:40:08 +11:00
|
|
|
|
2024-10-05 00:11:15 +10:00
|
|
|
expect(home_feed_ids(alice))
|
|
|
|
.to_not include(status.id)
|
|
|
|
expect(home_feed_ids(jeff))
|
|
|
|
.to_not include(status.id)
|
2024-01-09 20:40:08 +11:00
|
|
|
|
2024-10-05 00:11:15 +10:00
|
|
|
expect(redis)
|
|
|
|
.to have_received(:publish).with('timeline:public:media', Oj.dump(event: :delete, payload: status.id.to_s))
|
2024-06-17 20:21:29 +10:00
|
|
|
|
|
|
|
expect(delete_delivery(hank, status))
|
|
|
|
.to have_been_made.once
|
|
|
|
|
|
|
|
expect(delete_delivery(bill, status))
|
|
|
|
.to have_been_made.once
|
2022-02-12 00:52:07 +11:00
|
|
|
end
|
|
|
|
|
2024-10-05 00:11:15 +10:00
|
|
|
def home_feed_ids(personage)
|
|
|
|
HomeFeed
|
|
|
|
.new(personage)
|
|
|
|
.get(10)
|
|
|
|
.pluck(:id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_status_from_notifications
|
|
|
|
change { Notification.where(activity_type: 'Favourite', from_account: jeff, account: alice).count }
|
|
|
|
.from(1)
|
|
|
|
.to(0)
|
2022-02-12 00:52:07 +11:00
|
|
|
end
|
2024-06-17 20:21:29 +10:00
|
|
|
|
|
|
|
def delete_delivery(target, status)
|
|
|
|
a_request(:post, target.inbox_url)
|
|
|
|
.with(body: delete_activity_for(status))
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_activity_for(status)
|
|
|
|
hash_including(
|
|
|
|
'type' => 'Delete',
|
|
|
|
'object' => {
|
|
|
|
'type' => 'Tombstone',
|
|
|
|
'id' => ActivityPub::TagManager.instance.uri_for(status),
|
|
|
|
'atomUri' => OStatus::TagManager.instance.uri_for(status),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
2017-08-13 08:44:41 +10:00
|
|
|
end
|
|
|
|
|
2022-02-12 00:52:07 +11:00
|
|
|
context 'when removed status is a private self-reblog' do
|
2023-11-09 02:42:30 +11:00
|
|
|
let!(:original_status) { Fabricate(:status, account: alice, text: 'Hello ThisIsASecret', visibility: :private) }
|
|
|
|
let!(:status) { ReblogService.new.call(alice, original_status) }
|
2022-02-12 00:52:07 +11:00
|
|
|
|
|
|
|
it 'sends Undo activity to followers' do
|
2023-11-09 02:42:30 +11:00
|
|
|
subject.call(status)
|
2024-06-17 20:21:29 +10:00
|
|
|
|
|
|
|
expect(undo_delivery(hank, original_status))
|
|
|
|
.to have_been_made.once
|
2022-02-12 00:52:07 +11:00
|
|
|
end
|
2017-08-29 05:38:59 +10:00
|
|
|
end
|
2020-12-22 04:22:17 +11:00
|
|
|
|
2022-02-12 00:52:07 +11:00
|
|
|
context 'when removed status is public self-reblog' do
|
2023-11-09 02:42:30 +11:00
|
|
|
let!(:original_status) { Fabricate(:status, account: alice, text: 'Hello ThisIsASecret', visibility: :public) }
|
|
|
|
let!(:status) { ReblogService.new.call(alice, original_status) }
|
2022-02-12 00:52:07 +11:00
|
|
|
|
|
|
|
it 'sends Undo activity to followers' do
|
2023-11-09 02:42:30 +11:00
|
|
|
subject.call(status)
|
2024-06-17 20:21:29 +10:00
|
|
|
|
|
|
|
expect(undo_delivery(hank, original_status))
|
|
|
|
.to have_been_made.once
|
2022-02-12 00:52:07 +11:00
|
|
|
end
|
2020-12-22 04:22:17 +11:00
|
|
|
end
|
2024-01-13 02:58:28 +11:00
|
|
|
|
|
|
|
context 'when removed status is a reblog of a non-follower' do
|
|
|
|
let!(:original_status) { Fabricate(:status, account: bill, text: 'Hello ThisIsASecret', visibility: :public) }
|
|
|
|
let!(:status) { ReblogService.new.call(alice, original_status) }
|
|
|
|
|
|
|
|
it 'sends Undo activity to followers' do
|
|
|
|
subject.call(status)
|
2024-06-17 20:21:29 +10:00
|
|
|
|
|
|
|
expect(undo_delivery(bill, original_status))
|
|
|
|
.to have_been_made.once
|
2024-01-13 02:58:28 +11:00
|
|
|
end
|
|
|
|
end
|
2024-06-17 20:21:29 +10:00
|
|
|
|
|
|
|
def undo_delivery(target, status)
|
|
|
|
a_request(:post, target.inbox_url)
|
|
|
|
.with(body: undo_activity_for(status))
|
|
|
|
end
|
|
|
|
|
|
|
|
def undo_activity_for(status)
|
|
|
|
hash_including(
|
|
|
|
'type' => 'Undo',
|
|
|
|
'object' => hash_including(
|
|
|
|
'type' => 'Announce',
|
|
|
|
'object' => ActivityPub::TagManager.instance.uri_for(status)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
2017-06-12 01:13:43 +10:00
|
|
|
end
|