2023-02-22 01:55:31 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-15 03:56:41 +01:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 07:12:25 +02:00
|
|
|
RSpec.describe Account::Interactions do
|
2024-11-12 16:43:55 +01:00
|
|
|
let(:account) { Fabricate(:account) }
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:account_id) { account.id }
|
|
|
|
let(:account_ids) { [account_id] }
|
2024-11-12 16:43:55 +01:00
|
|
|
let(:target_account) { Fabricate(:account) }
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:target_account_id) { target_account.id }
|
|
|
|
let(:target_account_ids) { [target_account_id] }
|
|
|
|
|
|
|
|
describe '.following_map' do
|
|
|
|
subject { Account.following_map(target_account_ids, account_id) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when Account with Follow' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns { target_account_id => true }' do
|
|
|
|
Fabricate(:follow, account: account, target_account: target_account)
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to eq(target_account_id => { reblogs: true, notify: false, languages: nil })
|
2017-11-19 09:56:45 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Merge commit 'f877aa9d70d0d600961989b8e97c0e0ce3ac1db6' into glitch-soc/merge-upstream
Conflicts:
- `.github/dependabot.yml`:
Upstream made changes, but we had removed it.
Discarded upstream changes.
- `.rubocop_todo.yml`:
Upstream regenerated the file, we had some glitch-soc-specific ignores.
- `app/models/account_statuses_filter.rb`:
Minor upstream code style change where glitch-soc had slightly different code
due to handling of local-only posts.
Updated to match upstream's code style.
- `app/models/status.rb`:
Upstream moved ActiveRecord callback definitions, glitch-soc had an extra one.
Moved the definitions as upstream did.
- `app/services/backup_service.rb`:
Upstream rewrote a lot of the backup service, glitch-soc had changes because
of exporting local-only posts.
Took upstream changes and added back code to deal with local-only posts.
- `config/routes.rb`:
Upstream split the file into different files, while glitch-soc had a few
extra routes.
Extra routes added to `config/routes/settings.rb`, `config/routes/api.rb`
and `config/routes/admin.rb`
- `db/schema.rb`:
Upstream has new migrations, while glitch-soc had an extra migration.
Updated the expected serial number to match upstream's.
- `lib/mastodon/version.rb`:
Upstream added support to set version tags from environment variables, while
glitch-soc has an extra `+glitch` tag.
Changed the code to support upstream's feature but prepending a `+glitch`.
- `spec/lib/activitypub/activity/create_spec.rb`:
Minor code style change upstream, while glitch-soc has extra tests due to
`directMessage` handling.
Applied upstream's changes while keeping glitch-soc's extra tests.
- `spec/models/concerns/account_interactions_spec.rb`:
Minor code style change upstream, while glitch-soc has extra tests.
Applied upstream's changes while keeping glitch-soc's extra tests.
2023-05-08 19:05:55 +02:00
|
|
|
context 'when Account with Follow but with reblogs disabled' do
|
2017-11-19 09:56:45 +01:00
|
|
|
it 'returns { target_account_id => { reblogs: false } }' do
|
|
|
|
Fabricate(:follow, account: account, target_account: target_account, show_reblogs: false)
|
2023-04-09 11:25:30 +02:00
|
|
|
expect(subject).to eq(target_account_id => { reblogs: false, notify: false, languages: nil })
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when Account without Follow' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns {}' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to eq({})
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.followed_by_map' do
|
|
|
|
subject { Account.followed_by_map(target_account_ids, account_id) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when Account with Follow' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns { target_account_id => true }' do
|
|
|
|
Fabricate(:follow, account: target_account, target_account: account)
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to eq(target_account_id => true)
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when Account without Follow' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns {}' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to eq({})
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.blocking_map' do
|
|
|
|
subject { Account.blocking_map(target_account_ids, account_id) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when Account with Block' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns { target_account_id => true }' do
|
|
|
|
Fabricate(:block, account: account, target_account: target_account)
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to eq(target_account_id => true)
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when Account without Block' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns {}' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to eq({})
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.muting_map' do
|
|
|
|
subject { Account.muting_map(target_account_ids, account_id) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when Account with Mute' do
|
2017-11-19 04:16:14 +01:00
|
|
|
before do
|
|
|
|
Fabricate(:mute, target_account: target_account, account: account, hide_notifications: hide)
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when Mute#hide_notifications?' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:hide) { true }
|
|
|
|
|
|
|
|
it 'returns { target_account_id => { notifications: true } }' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to eq(target_account_id => { notifications: true })
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when not Mute#hide_notifications?' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:hide) { false }
|
|
|
|
|
|
|
|
it 'returns { target_account_id => { notifications: false } }' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to eq(target_account_id => { notifications: false })
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when Account without Mute' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns {}' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to eq({})
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#follow!' do
|
|
|
|
it 'creates and returns Follow' do
|
|
|
|
expect do
|
2023-02-18 03:24:16 +01:00
|
|
|
expect(account.follow!(target_account)).to be_a Follow
|
2017-11-19 04:16:14 +01:00
|
|
|
end.to change { account.following.count }.by 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#block' do
|
|
|
|
it 'creates and returns Block' do
|
|
|
|
expect do
|
2023-02-18 03:24:16 +01:00
|
|
|
expect(account.block!(target_account)).to be_a Block
|
2017-11-19 04:16:14 +01:00
|
|
|
end.to change { account.block_relationships.count }.by 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#mute!' do
|
2018-05-02 16:14:51 +02:00
|
|
|
subject { account.mute!(target_account, notifications: arg_notifications) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when Mute does not exist yet' do
|
|
|
|
context 'when arg :notifications is nil' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:arg_notifications) { nil }
|
|
|
|
|
2018-05-02 16:14:51 +02:00
|
|
|
it 'creates Mute, and returns Mute' do
|
2017-11-19 04:16:14 +01:00
|
|
|
expect do
|
2023-02-18 03:24:16 +01:00
|
|
|
expect(subject).to be_a Mute
|
2017-11-19 04:16:14 +01:00
|
|
|
end.to change { account.mute_relationships.count }.by 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when arg :notifications is false' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:arg_notifications) { false }
|
|
|
|
|
2018-05-02 16:14:51 +02:00
|
|
|
it 'creates Mute, and returns Mute' do
|
2017-11-19 04:16:14 +01:00
|
|
|
expect do
|
2023-02-18 03:24:16 +01:00
|
|
|
expect(subject).to be_a Mute
|
2017-11-19 04:16:14 +01:00
|
|
|
end.to change { account.mute_relationships.count }.by 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when arg :notifications is true' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:arg_notifications) { true }
|
|
|
|
|
2018-05-02 16:14:51 +02:00
|
|
|
it 'creates Mute, and returns Mute' do
|
2017-11-19 04:16:14 +01:00
|
|
|
expect do
|
2023-02-18 03:24:16 +01:00
|
|
|
expect(subject).to be_a Mute
|
2017-11-19 04:16:14 +01:00
|
|
|
end.to change { account.mute_relationships.count }.by 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when Mute already exists' do
|
2017-11-19 04:16:14 +01:00
|
|
|
before do
|
|
|
|
account.mute_relationships << mute
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:mute) do
|
|
|
|
Fabricate(:mute,
|
2023-02-20 06:58:28 +01:00
|
|
|
account: account,
|
|
|
|
target_account: target_account,
|
2017-11-19 04:16:14 +01:00
|
|
|
hide_notifications: hide_notifications)
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when mute.hide_notifications is true' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:hide_notifications) { true }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when arg :notifications is nil' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:arg_notifications) { nil }
|
|
|
|
|
2018-05-02 16:14:51 +02:00
|
|
|
it 'returns Mute without updating mute.hide_notifications' do
|
2017-11-19 04:16:14 +01:00
|
|
|
expect do
|
2023-02-18 03:24:16 +01:00
|
|
|
expect(subject).to be_a Mute
|
2023-02-20 02:33:27 +01:00
|
|
|
end.to_not change { mute.reload.hide_notifications? }.from(true)
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when arg :notifications is false' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:arg_notifications) { false }
|
|
|
|
|
2018-05-02 16:14:51 +02:00
|
|
|
it 'returns Mute, and updates mute.hide_notifications false' do
|
2017-11-19 04:16:14 +01:00
|
|
|
expect do
|
2023-02-18 03:24:16 +01:00
|
|
|
expect(subject).to be_a Mute
|
2018-05-02 16:14:51 +02:00
|
|
|
end.to change { mute.reload.hide_notifications? }.from(true).to(false)
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when arg :notifications is true' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:arg_notifications) { true }
|
|
|
|
|
2018-05-02 16:14:51 +02:00
|
|
|
it 'returns Mute without updating mute.hide_notifications' do
|
2017-11-19 04:16:14 +01:00
|
|
|
expect do
|
2023-02-18 03:24:16 +01:00
|
|
|
expect(subject).to be_a Mute
|
2023-02-20 02:33:27 +01:00
|
|
|
end.to_not change { mute.reload.hide_notifications? }.from(true)
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when mute.hide_notifications is false' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:hide_notifications) { false }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when arg :notifications is nil' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:arg_notifications) { nil }
|
|
|
|
|
2018-05-02 16:14:51 +02:00
|
|
|
it 'returns Mute, and updates mute.hide_notifications true' do
|
2017-11-19 04:16:14 +01:00
|
|
|
expect do
|
2023-02-18 03:24:16 +01:00
|
|
|
expect(subject).to be_a Mute
|
2018-05-02 16:14:51 +02:00
|
|
|
end.to change { mute.reload.hide_notifications? }.from(false).to(true)
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when arg :notifications is false' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:arg_notifications) { false }
|
|
|
|
|
2018-05-02 16:14:51 +02:00
|
|
|
it 'returns Mute without updating mute.hide_notifications' do
|
2017-11-19 04:16:14 +01:00
|
|
|
expect do
|
2023-02-18 03:24:16 +01:00
|
|
|
expect(subject).to be_a Mute
|
2023-02-20 02:33:27 +01:00
|
|
|
end.to_not change { mute.reload.hide_notifications? }.from(false)
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when arg :notifications is true' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:arg_notifications) { true }
|
|
|
|
|
2018-05-02 16:14:51 +02:00
|
|
|
it 'returns Mute, and updates mute.hide_notifications true' do
|
2017-11-19 04:16:14 +01:00
|
|
|
expect do
|
2023-02-18 03:24:16 +01:00
|
|
|
expect(subject).to be_a Mute
|
2018-05-02 16:14:51 +02:00
|
|
|
end.to change { mute.reload.hide_notifications? }.from(false).to(true)
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#mute_conversation!' do
|
|
|
|
subject { account.mute_conversation!(conversation) }
|
|
|
|
|
2023-02-20 05:24:14 +01:00
|
|
|
let(:conversation) { Fabricate(:conversation) }
|
|
|
|
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'creates and returns ConversationMute' do
|
|
|
|
expect do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be_a ConversationMute
|
2017-11-19 04:16:14 +01:00
|
|
|
end.to change { account.conversation_mutes.count }.by 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#block_domain!' do
|
2019-02-03 03:59:51 +01:00
|
|
|
subject { account.block_domain!(domain) }
|
2017-11-19 04:16:14 +01:00
|
|
|
|
2023-02-20 05:24:14 +01:00
|
|
|
let(:domain) { 'example.com' }
|
|
|
|
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'creates and returns AccountDomainBlock' do
|
|
|
|
expect do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be_a AccountDomainBlock
|
2017-11-19 04:16:14 +01:00
|
|
|
end.to change { account.domain_blocks.count }.by 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-03-11 10:28:08 +01:00
|
|
|
describe '#block_idna_domain!' do
|
|
|
|
subject do
|
|
|
|
[
|
|
|
|
account.block_domain!(idna_domain),
|
|
|
|
account.block_domain!(punycode_domain),
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:idna_domain) { '대한민국.한국' }
|
|
|
|
let(:punycode_domain) { 'xn--3e0bs9hfvinn1a.xn--3e0b707e' }
|
|
|
|
|
|
|
|
it 'creates single AccountDomainBlock' do
|
|
|
|
expect do
|
|
|
|
expect(subject).to all(be_a AccountDomainBlock)
|
|
|
|
end.to change { account.domain_blocks.count }.by 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-19 04:16:14 +01:00
|
|
|
describe '#unfollow!' do
|
|
|
|
subject { account.unfollow!(target_account) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when following target_account' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns destroyed Follow' do
|
|
|
|
account.active_relationships.create(target_account: target_account)
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be_a Follow
|
2017-11-19 04:16:14 +01:00
|
|
|
expect(subject).to be_destroyed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when not following target_account' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns nil' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be_nil
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#unblock!' do
|
|
|
|
subject { account.unblock!(target_account) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when blocking target_account' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns destroyed Block' do
|
|
|
|
account.block_relationships.create(target_account: target_account)
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be_a Block
|
2017-11-19 04:16:14 +01:00
|
|
|
expect(subject).to be_destroyed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when not blocking target_account' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns nil' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be_nil
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#unmute!' do
|
|
|
|
subject { account.unmute!(target_account) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when muting target_account' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns destroyed Mute' do
|
|
|
|
account.mute_relationships.create(target_account: target_account)
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be_a Mute
|
2017-11-19 04:16:14 +01:00
|
|
|
expect(subject).to be_destroyed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when not muting target_account' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns nil' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be_nil
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#unmute_conversation!' do
|
|
|
|
subject { account.unmute_conversation!(conversation) }
|
|
|
|
|
2023-02-20 05:24:14 +01:00
|
|
|
let(:conversation) { Fabricate(:conversation) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when muting the conversation' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns destroyed ConversationMute' do
|
|
|
|
account.conversation_mutes.create(conversation: conversation)
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be_a ConversationMute
|
2017-11-19 04:16:14 +01:00
|
|
|
expect(subject).to be_destroyed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when not muting the conversation' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns nil' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be_nil
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#unblock_domain!' do
|
|
|
|
subject { account.unblock_domain!(domain) }
|
|
|
|
|
2023-02-20 05:24:14 +01:00
|
|
|
let(:domain) { 'example.com' }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when blocking the domain' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns destroyed AccountDomainBlock' do
|
|
|
|
account_domain_block = Fabricate(:account_domain_block, domain: domain)
|
|
|
|
account.domain_blocks << account_domain_block
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be_a AccountDomainBlock
|
2017-11-19 04:16:14 +01:00
|
|
|
expect(subject).to be_destroyed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when unblocking the domain' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns nil' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be_nil
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-03-11 10:28:08 +01:00
|
|
|
describe '#unblock_idna_domain!' do
|
|
|
|
subject { account.unblock_domain!(punycode_domain) }
|
|
|
|
|
|
|
|
let(:idna_domain) { '대한민국.한국' }
|
|
|
|
let(:punycode_domain) { 'xn--3e0bs9hfvinn1a.xn--3e0b707e' }
|
|
|
|
|
|
|
|
context 'when blocking the domain' do
|
|
|
|
it 'returns destroyed AccountDomainBlock' do
|
|
|
|
account_domain_block = Fabricate(:account_domain_block, domain: idna_domain)
|
|
|
|
account.domain_blocks << account_domain_block
|
|
|
|
expect(subject).to be_a AccountDomainBlock
|
|
|
|
expect(subject).to be_destroyed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unblocking idna domain' do
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(subject).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-19 04:16:14 +01:00
|
|
|
describe '#following?' do
|
|
|
|
subject { account.following?(target_account) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when following target_account' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns true' do
|
|
|
|
account.active_relationships.create(target_account: target_account)
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be true
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when not following target_account' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns false' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be false
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-10-18 12:02:35 +02:00
|
|
|
describe '#followed_by?' do
|
|
|
|
subject { account.followed_by?(target_account) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when followed by target_account' do
|
2021-10-18 12:02:35 +02:00
|
|
|
it 'returns true' do
|
|
|
|
account.passive_relationships.create(account: target_account)
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be true
|
2021-10-18 12:02:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when not followed by target_account' do
|
2021-10-18 12:02:35 +02:00
|
|
|
it 'returns false' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be false
|
2021-10-18 12:02:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-19 04:16:14 +01:00
|
|
|
describe '#blocking?' do
|
|
|
|
subject { account.blocking?(target_account) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when blocking target_account' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns true' do
|
|
|
|
account.block_relationships.create(target_account: target_account)
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be true
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when not blocking target_account' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns false' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be false
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#domain_blocking?' do
|
|
|
|
subject { account.domain_blocking?(domain) }
|
|
|
|
|
2023-02-20 05:24:14 +01:00
|
|
|
let(:domain) { 'example.com' }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when blocking the domain' do
|
2023-02-18 12:47:37 +01:00
|
|
|
it 'returns true' do
|
2017-11-19 04:16:14 +01:00
|
|
|
account_domain_block = Fabricate(:account_domain_block, domain: domain)
|
|
|
|
account.domain_blocks << account_domain_block
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be true
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when not blocking the domain' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns false' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be false
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#muting?' do
|
|
|
|
subject { account.muting?(target_account) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when muting target_account' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns true' do
|
|
|
|
mute = Fabricate(:mute, account: account, target_account: target_account)
|
|
|
|
account.mute_relationships << mute
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be true
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when not muting target_account' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns false' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be false
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#muting_conversation?' do
|
|
|
|
subject { account.muting_conversation?(conversation) }
|
|
|
|
|
2023-02-20 05:24:14 +01:00
|
|
|
let(:conversation) { Fabricate(:conversation) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when muting the conversation' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns true' do
|
|
|
|
account.conversation_mutes.create(conversation: conversation)
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be true
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when not muting the conversation' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns false' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be false
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#muting_notifications?' do
|
2023-02-20 05:24:14 +01:00
|
|
|
subject { account.muting_notifications?(target_account) }
|
|
|
|
|
2017-11-19 04:16:14 +01:00
|
|
|
before do
|
|
|
|
mute = Fabricate(:mute, target_account: target_account, account: account, hide_notifications: hide)
|
|
|
|
account.mute_relationships << mute
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when muting notifications of target_account' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:hide) { true }
|
|
|
|
|
|
|
|
it 'returns true' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be true
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when not muting notifications of target_account' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:hide) { false }
|
|
|
|
|
|
|
|
it 'returns false' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be false
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#requested?' do
|
|
|
|
subject { account.requested?(target_account) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'with requested by target_account' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns true' do
|
|
|
|
Fabricate(:follow_request, account: account, target_account: target_account)
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be true
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when not requested by target_account' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns false' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be false
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#favourited?' do
|
|
|
|
subject { account.favourited?(status) }
|
|
|
|
|
2023-02-20 05:24:14 +01:00
|
|
|
let(:status) { Fabricate(:status, account: account, favourites: favourites) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when favorited' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:favourites) { [Fabricate(:favourite, account: account)] }
|
|
|
|
|
|
|
|
it 'returns true' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be true
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when not favorited' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:favourites) { [] }
|
|
|
|
|
|
|
|
it 'returns false' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be false
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#reblogged?' do
|
|
|
|
subject { account.reblogged?(status) }
|
|
|
|
|
2023-02-20 05:24:14 +01:00
|
|
|
let(:status) { Fabricate(:status, account: account, reblogs: reblogs) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'with reblogged' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:reblogs) { [Fabricate(:status, account: account)] }
|
|
|
|
|
|
|
|
it 'returns true' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be true
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when not reblogged' do
|
2017-11-19 04:16:14 +01:00
|
|
|
let(:reblogs) { [] }
|
|
|
|
|
|
|
|
it 'returns false' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be false
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#pinned?' do
|
|
|
|
subject { account.pinned?(status) }
|
|
|
|
|
2023-02-20 05:24:14 +01:00
|
|
|
let(:status) { Fabricate(:status, account: account) }
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when pinned' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns true' do
|
|
|
|
Fabricate(:status_pin, account: account, status: status)
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be true
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when not pinned' do
|
2017-11-19 04:16:14 +01:00
|
|
|
it 'returns false' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to be false
|
2017-11-19 04:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-11 17:48:42 +02:00
|
|
|
describe '#remote_followers_hash' do
|
Add follower synchronization mechanism (#14510)
* Add support for followers synchronization on the receiving end
Check the `collectionSynchronization` attribute on `Create` and `Announce`
activities and synchronize followers from provided collection if possible.
* Add tests for followers synchronization on the receiving end
* Add support for follower synchronization on the sender's end
* Add tests for the sending end
* Switch from AS attributes to HTTP header
Replace the custom `collectionSynchronization` ActivityStreams attribute by
an HTTP header (`X-AS-Collection-Synchronization`) with the same syntax as
the `Signature` header and the following fields:
- `collectionId` to specify which collection to synchronize
- `digest` for the SHA256 hex-digest of the list of followers known on the
receiving instance (where “receiving instance” is determined by accounts
sharing the same host name for their ActivityPub actor `id`)
- `url` of a collection that should be fetched by the instance actor
Internally, move away from the webfinger-based `domain` attribute and use
account `uri` prefix to group accounts.
* Add environment variable to disable followers synchronization
Since the whole mechanism relies on some new preconditions that, in some
extremely rare cases, might not be met, add an environment variable
(DISABLE_FOLLOWERS_SYNCHRONIZATION) to disable the mechanism altogether and
avoid followers being incorrectly removed.
The current conditions are:
1. all managed accounts' actor `id` and inbox URL have the same URI scheme and
netloc.
2. all accounts whose actor `id` or inbox URL share the same URI scheme and
netloc as a managed account must be managed by the same Mastodon instance
as well.
As far as Mastodon is concerned, breaking those preconditions require extensive
configuration changes in the reverse proxy and might also cause other issues.
Therefore, this environment variable provides a way out for people with highly
unusual configurations, and can be safely ignored for the overwhelming majority
of Mastodon administrators.
* Only set follower synchronization header on non-public statuses
This is to avoid unnecessary computations and allow Follow-related
activities to be handled by the usual codepath instead of going through
the synchronization mechanism (otherwise, any Follow/Undo/Accept activity
would trigger the synchronization mechanism even if processing the activity
itself would be enough to re-introduce synchronization)
* Change how ActivityPub::SynchronizeFollowersService handles follow requests
If the remote lists a local follower which we only know has sent a follow
request, consider the follow request as accepted instead of sending an Undo.
* Integrate review feeback
- rename X-AS-Collection-Synchronization to Collection-Synchronization
- various minor refactoring and code style changes
* Only select required fields when computing followers_hash
* Use actor URI rather than webfinger domain in synchronization endpoint
* Change hash computation to be a XOR of individual hashes
Makes it much easier to be memory-efficient, and avoid sorting discrepancy issues.
* Marginally improve followers_hash computation speed
* Further improve hash computation performances by using pluck_each
2020-10-21 18:04:09 +02:00
|
|
|
let(:me) { Fabricate(:account, username: 'Me') }
|
2023-06-14 16:44:37 +02:00
|
|
|
let(:remote_alice) { Fabricate(:account, username: 'alice', domain: 'example.org', uri: 'https://example.org/users/alice') }
|
|
|
|
let(:remote_bob) { Fabricate(:account, username: 'bob', domain: 'example.org', uri: 'https://example.org/users/bob') }
|
|
|
|
let(:remote_instance_actor) { Fabricate(:account, username: 'instance-actor', domain: 'example.org', uri: 'https://example.org') }
|
|
|
|
let(:remote_eve) { Fabricate(:account, username: 'eve', domain: 'foo.org', uri: 'https://foo.org/users/eve') }
|
Add follower synchronization mechanism (#14510)
* Add support for followers synchronization on the receiving end
Check the `collectionSynchronization` attribute on `Create` and `Announce`
activities and synchronize followers from provided collection if possible.
* Add tests for followers synchronization on the receiving end
* Add support for follower synchronization on the sender's end
* Add tests for the sending end
* Switch from AS attributes to HTTP header
Replace the custom `collectionSynchronization` ActivityStreams attribute by
an HTTP header (`X-AS-Collection-Synchronization`) with the same syntax as
the `Signature` header and the following fields:
- `collectionId` to specify which collection to synchronize
- `digest` for the SHA256 hex-digest of the list of followers known on the
receiving instance (where “receiving instance” is determined by accounts
sharing the same host name for their ActivityPub actor `id`)
- `url` of a collection that should be fetched by the instance actor
Internally, move away from the webfinger-based `domain` attribute and use
account `uri` prefix to group accounts.
* Add environment variable to disable followers synchronization
Since the whole mechanism relies on some new preconditions that, in some
extremely rare cases, might not be met, add an environment variable
(DISABLE_FOLLOWERS_SYNCHRONIZATION) to disable the mechanism altogether and
avoid followers being incorrectly removed.
The current conditions are:
1. all managed accounts' actor `id` and inbox URL have the same URI scheme and
netloc.
2. all accounts whose actor `id` or inbox URL share the same URI scheme and
netloc as a managed account must be managed by the same Mastodon instance
as well.
As far as Mastodon is concerned, breaking those preconditions require extensive
configuration changes in the reverse proxy and might also cause other issues.
Therefore, this environment variable provides a way out for people with highly
unusual configurations, and can be safely ignored for the overwhelming majority
of Mastodon administrators.
* Only set follower synchronization header on non-public statuses
This is to avoid unnecessary computations and allow Follow-related
activities to be handled by the usual codepath instead of going through
the synchronization mechanism (otherwise, any Follow/Undo/Accept activity
would trigger the synchronization mechanism even if processing the activity
itself would be enough to re-introduce synchronization)
* Change how ActivityPub::SynchronizeFollowersService handles follow requests
If the remote lists a local follower which we only know has sent a follow
request, consider the follow request as accepted instead of sending an Undo.
* Integrate review feeback
- rename X-AS-Collection-Synchronization to Collection-Synchronization
- various minor refactoring and code style changes
* Only select required fields when computing followers_hash
* Use actor URI rather than webfinger domain in synchronization endpoint
* Change hash computation to be a XOR of individual hashes
Makes it much easier to be memory-efficient, and avoid sorting discrepancy issues.
* Marginally improve followers_hash computation speed
* Further improve hash computation performances by using pluck_each
2020-10-21 18:04:09 +02:00
|
|
|
|
|
|
|
before do
|
2023-06-14 16:44:37 +02:00
|
|
|
remote_alice.follow!(me)
|
|
|
|
remote_bob.follow!(me)
|
|
|
|
remote_instance_actor.follow!(me)
|
|
|
|
remote_eve.follow!(me)
|
|
|
|
me.follow!(remote_alice)
|
Add follower synchronization mechanism (#14510)
* Add support for followers synchronization on the receiving end
Check the `collectionSynchronization` attribute on `Create` and `Announce`
activities and synchronize followers from provided collection if possible.
* Add tests for followers synchronization on the receiving end
* Add support for follower synchronization on the sender's end
* Add tests for the sending end
* Switch from AS attributes to HTTP header
Replace the custom `collectionSynchronization` ActivityStreams attribute by
an HTTP header (`X-AS-Collection-Synchronization`) with the same syntax as
the `Signature` header and the following fields:
- `collectionId` to specify which collection to synchronize
- `digest` for the SHA256 hex-digest of the list of followers known on the
receiving instance (where “receiving instance” is determined by accounts
sharing the same host name for their ActivityPub actor `id`)
- `url` of a collection that should be fetched by the instance actor
Internally, move away from the webfinger-based `domain` attribute and use
account `uri` prefix to group accounts.
* Add environment variable to disable followers synchronization
Since the whole mechanism relies on some new preconditions that, in some
extremely rare cases, might not be met, add an environment variable
(DISABLE_FOLLOWERS_SYNCHRONIZATION) to disable the mechanism altogether and
avoid followers being incorrectly removed.
The current conditions are:
1. all managed accounts' actor `id` and inbox URL have the same URI scheme and
netloc.
2. all accounts whose actor `id` or inbox URL share the same URI scheme and
netloc as a managed account must be managed by the same Mastodon instance
as well.
As far as Mastodon is concerned, breaking those preconditions require extensive
configuration changes in the reverse proxy and might also cause other issues.
Therefore, this environment variable provides a way out for people with highly
unusual configurations, and can be safely ignored for the overwhelming majority
of Mastodon administrators.
* Only set follower synchronization header on non-public statuses
This is to avoid unnecessary computations and allow Follow-related
activities to be handled by the usual codepath instead of going through
the synchronization mechanism (otherwise, any Follow/Undo/Accept activity
would trigger the synchronization mechanism even if processing the activity
itself would be enough to re-introduce synchronization)
* Change how ActivityPub::SynchronizeFollowersService handles follow requests
If the remote lists a local follower which we only know has sent a follow
request, consider the follow request as accepted instead of sending an Undo.
* Integrate review feeback
- rename X-AS-Collection-Synchronization to Collection-Synchronization
- various minor refactoring and code style changes
* Only select required fields when computing followers_hash
* Use actor URI rather than webfinger domain in synchronization endpoint
* Change hash computation to be a XOR of individual hashes
Makes it much easier to be memory-efficient, and avoid sorting discrepancy issues.
* Marginally improve followers_hash computation speed
* Further improve hash computation performances by using pluck_each
2020-10-21 18:04:09 +02:00
|
|
|
end
|
|
|
|
|
2021-08-11 17:48:42 +02:00
|
|
|
it 'returns correct hash for remote domains' do
|
|
|
|
expect(me.remote_followers_hash('https://example.org/')).to eq '20aecbe774b3d61c25094370baf370012b9271c5b172ecedb05caff8d79ef0c7'
|
|
|
|
expect(me.remote_followers_hash('https://foo.org/')).to eq 'ccb9c18a67134cfff9d62c7f7e7eb88e6b803446c244b84265565f4eba29df0e'
|
|
|
|
expect(me.remote_followers_hash('https://foo.org.evil.com/')).to eq '0000000000000000000000000000000000000000000000000000000000000000'
|
|
|
|
expect(me.remote_followers_hash('https://foo')).to eq '0000000000000000000000000000000000000000000000000000000000000000'
|
|
|
|
end
|
Add follower synchronization mechanism (#14510)
* Add support for followers synchronization on the receiving end
Check the `collectionSynchronization` attribute on `Create` and `Announce`
activities and synchronize followers from provided collection if possible.
* Add tests for followers synchronization on the receiving end
* Add support for follower synchronization on the sender's end
* Add tests for the sending end
* Switch from AS attributes to HTTP header
Replace the custom `collectionSynchronization` ActivityStreams attribute by
an HTTP header (`X-AS-Collection-Synchronization`) with the same syntax as
the `Signature` header and the following fields:
- `collectionId` to specify which collection to synchronize
- `digest` for the SHA256 hex-digest of the list of followers known on the
receiving instance (where “receiving instance” is determined by accounts
sharing the same host name for their ActivityPub actor `id`)
- `url` of a collection that should be fetched by the instance actor
Internally, move away from the webfinger-based `domain` attribute and use
account `uri` prefix to group accounts.
* Add environment variable to disable followers synchronization
Since the whole mechanism relies on some new preconditions that, in some
extremely rare cases, might not be met, add an environment variable
(DISABLE_FOLLOWERS_SYNCHRONIZATION) to disable the mechanism altogether and
avoid followers being incorrectly removed.
The current conditions are:
1. all managed accounts' actor `id` and inbox URL have the same URI scheme and
netloc.
2. all accounts whose actor `id` or inbox URL share the same URI scheme and
netloc as a managed account must be managed by the same Mastodon instance
as well.
As far as Mastodon is concerned, breaking those preconditions require extensive
configuration changes in the reverse proxy and might also cause other issues.
Therefore, this environment variable provides a way out for people with highly
unusual configurations, and can be safely ignored for the overwhelming majority
of Mastodon administrators.
* Only set follower synchronization header on non-public statuses
This is to avoid unnecessary computations and allow Follow-related
activities to be handled by the usual codepath instead of going through
the synchronization mechanism (otherwise, any Follow/Undo/Accept activity
would trigger the synchronization mechanism even if processing the activity
itself would be enough to re-introduce synchronization)
* Change how ActivityPub::SynchronizeFollowersService handles follow requests
If the remote lists a local follower which we only know has sent a follow
request, consider the follow request as accepted instead of sending an Undo.
* Integrate review feeback
- rename X-AS-Collection-Synchronization to Collection-Synchronization
- various minor refactoring and code style changes
* Only select required fields when computing followers_hash
* Use actor URI rather than webfinger domain in synchronization endpoint
* Change hash computation to be a XOR of individual hashes
Makes it much easier to be memory-efficient, and avoid sorting discrepancy issues.
* Marginally improve followers_hash computation speed
* Further improve hash computation performances by using pluck_each
2020-10-21 18:04:09 +02:00
|
|
|
|
2021-08-11 17:48:42 +02:00
|
|
|
it 'invalidates cache as needed when removing or adding followers' do
|
|
|
|
expect(me.remote_followers_hash('https://example.org/')).to eq '20aecbe774b3d61c25094370baf370012b9271c5b172ecedb05caff8d79ef0c7'
|
2023-06-14 16:44:37 +02:00
|
|
|
remote_instance_actor.unfollow!(me)
|
2021-08-11 17:48:42 +02:00
|
|
|
expect(me.remote_followers_hash('https://example.org/')).to eq '707962e297b7bd94468a21bc8e506a1bcea607a9142cd64e27c9b106b2a5f6ec'
|
2023-06-14 16:44:37 +02:00
|
|
|
remote_alice.unfollow!(me)
|
2021-08-11 17:48:42 +02:00
|
|
|
expect(me.remote_followers_hash('https://example.org/')).to eq '241b00794ce9b46aa864f3220afadef128318da2659782985bac5ed5bd436bff'
|
2023-06-14 16:44:37 +02:00
|
|
|
remote_alice.follow!(me)
|
2021-08-11 17:48:42 +02:00
|
|
|
expect(me.remote_followers_hash('https://example.org/')).to eq '707962e297b7bd94468a21bc8e506a1bcea607a9142cd64e27c9b106b2a5f6ec'
|
Add follower synchronization mechanism (#14510)
* Add support for followers synchronization on the receiving end
Check the `collectionSynchronization` attribute on `Create` and `Announce`
activities and synchronize followers from provided collection if possible.
* Add tests for followers synchronization on the receiving end
* Add support for follower synchronization on the sender's end
* Add tests for the sending end
* Switch from AS attributes to HTTP header
Replace the custom `collectionSynchronization` ActivityStreams attribute by
an HTTP header (`X-AS-Collection-Synchronization`) with the same syntax as
the `Signature` header and the following fields:
- `collectionId` to specify which collection to synchronize
- `digest` for the SHA256 hex-digest of the list of followers known on the
receiving instance (where “receiving instance” is determined by accounts
sharing the same host name for their ActivityPub actor `id`)
- `url` of a collection that should be fetched by the instance actor
Internally, move away from the webfinger-based `domain` attribute and use
account `uri` prefix to group accounts.
* Add environment variable to disable followers synchronization
Since the whole mechanism relies on some new preconditions that, in some
extremely rare cases, might not be met, add an environment variable
(DISABLE_FOLLOWERS_SYNCHRONIZATION) to disable the mechanism altogether and
avoid followers being incorrectly removed.
The current conditions are:
1. all managed accounts' actor `id` and inbox URL have the same URI scheme and
netloc.
2. all accounts whose actor `id` or inbox URL share the same URI scheme and
netloc as a managed account must be managed by the same Mastodon instance
as well.
As far as Mastodon is concerned, breaking those preconditions require extensive
configuration changes in the reverse proxy and might also cause other issues.
Therefore, this environment variable provides a way out for people with highly
unusual configurations, and can be safely ignored for the overwhelming majority
of Mastodon administrators.
* Only set follower synchronization header on non-public statuses
This is to avoid unnecessary computations and allow Follow-related
activities to be handled by the usual codepath instead of going through
the synchronization mechanism (otherwise, any Follow/Undo/Accept activity
would trigger the synchronization mechanism even if processing the activity
itself would be enough to re-introduce synchronization)
* Change how ActivityPub::SynchronizeFollowersService handles follow requests
If the remote lists a local follower which we only know has sent a follow
request, consider the follow request as accepted instead of sending an Undo.
* Integrate review feeback
- rename X-AS-Collection-Synchronization to Collection-Synchronization
- various minor refactoring and code style changes
* Only select required fields when computing followers_hash
* Use actor URI rather than webfinger domain in synchronization endpoint
* Change hash computation to be a XOR of individual hashes
Makes it much easier to be memory-efficient, and avoid sorting discrepancy issues.
* Marginally improve followers_hash computation speed
* Further improve hash computation performances by using pluck_each
2020-10-21 18:04:09 +02:00
|
|
|
end
|
2021-08-11 17:48:42 +02:00
|
|
|
end
|
Add follower synchronization mechanism (#14510)
* Add support for followers synchronization on the receiving end
Check the `collectionSynchronization` attribute on `Create` and `Announce`
activities and synchronize followers from provided collection if possible.
* Add tests for followers synchronization on the receiving end
* Add support for follower synchronization on the sender's end
* Add tests for the sending end
* Switch from AS attributes to HTTP header
Replace the custom `collectionSynchronization` ActivityStreams attribute by
an HTTP header (`X-AS-Collection-Synchronization`) with the same syntax as
the `Signature` header and the following fields:
- `collectionId` to specify which collection to synchronize
- `digest` for the SHA256 hex-digest of the list of followers known on the
receiving instance (where “receiving instance” is determined by accounts
sharing the same host name for their ActivityPub actor `id`)
- `url` of a collection that should be fetched by the instance actor
Internally, move away from the webfinger-based `domain` attribute and use
account `uri` prefix to group accounts.
* Add environment variable to disable followers synchronization
Since the whole mechanism relies on some new preconditions that, in some
extremely rare cases, might not be met, add an environment variable
(DISABLE_FOLLOWERS_SYNCHRONIZATION) to disable the mechanism altogether and
avoid followers being incorrectly removed.
The current conditions are:
1. all managed accounts' actor `id` and inbox URL have the same URI scheme and
netloc.
2. all accounts whose actor `id` or inbox URL share the same URI scheme and
netloc as a managed account must be managed by the same Mastodon instance
as well.
As far as Mastodon is concerned, breaking those preconditions require extensive
configuration changes in the reverse proxy and might also cause other issues.
Therefore, this environment variable provides a way out for people with highly
unusual configurations, and can be safely ignored for the overwhelming majority
of Mastodon administrators.
* Only set follower synchronization header on non-public statuses
This is to avoid unnecessary computations and allow Follow-related
activities to be handled by the usual codepath instead of going through
the synchronization mechanism (otherwise, any Follow/Undo/Accept activity
would trigger the synchronization mechanism even if processing the activity
itself would be enough to re-introduce synchronization)
* Change how ActivityPub::SynchronizeFollowersService handles follow requests
If the remote lists a local follower which we only know has sent a follow
request, consider the follow request as accepted instead of sending an Undo.
* Integrate review feeback
- rename X-AS-Collection-Synchronization to Collection-Synchronization
- various minor refactoring and code style changes
* Only select required fields when computing followers_hash
* Use actor URI rather than webfinger domain in synchronization endpoint
* Change hash computation to be a XOR of individual hashes
Makes it much easier to be memory-efficient, and avoid sorting discrepancy issues.
* Marginally improve followers_hash computation speed
* Further improve hash computation performances by using pluck_each
2020-10-21 18:04:09 +02:00
|
|
|
|
2021-08-11 17:48:42 +02:00
|
|
|
describe '#local_followers_hash' do
|
|
|
|
let(:me) { Fabricate(:account, username: 'Me') }
|
2023-06-14 16:44:37 +02:00
|
|
|
let(:remote_alice) { Fabricate(:account, username: 'alice', domain: 'example.org', uri: 'https://example.org/users/alice') }
|
Add follower synchronization mechanism (#14510)
* Add support for followers synchronization on the receiving end
Check the `collectionSynchronization` attribute on `Create` and `Announce`
activities and synchronize followers from provided collection if possible.
* Add tests for followers synchronization on the receiving end
* Add support for follower synchronization on the sender's end
* Add tests for the sending end
* Switch from AS attributes to HTTP header
Replace the custom `collectionSynchronization` ActivityStreams attribute by
an HTTP header (`X-AS-Collection-Synchronization`) with the same syntax as
the `Signature` header and the following fields:
- `collectionId` to specify which collection to synchronize
- `digest` for the SHA256 hex-digest of the list of followers known on the
receiving instance (where “receiving instance” is determined by accounts
sharing the same host name for their ActivityPub actor `id`)
- `url` of a collection that should be fetched by the instance actor
Internally, move away from the webfinger-based `domain` attribute and use
account `uri` prefix to group accounts.
* Add environment variable to disable followers synchronization
Since the whole mechanism relies on some new preconditions that, in some
extremely rare cases, might not be met, add an environment variable
(DISABLE_FOLLOWERS_SYNCHRONIZATION) to disable the mechanism altogether and
avoid followers being incorrectly removed.
The current conditions are:
1. all managed accounts' actor `id` and inbox URL have the same URI scheme and
netloc.
2. all accounts whose actor `id` or inbox URL share the same URI scheme and
netloc as a managed account must be managed by the same Mastodon instance
as well.
As far as Mastodon is concerned, breaking those preconditions require extensive
configuration changes in the reverse proxy and might also cause other issues.
Therefore, this environment variable provides a way out for people with highly
unusual configurations, and can be safely ignored for the overwhelming majority
of Mastodon administrators.
* Only set follower synchronization header on non-public statuses
This is to avoid unnecessary computations and allow Follow-related
activities to be handled by the usual codepath instead of going through
the synchronization mechanism (otherwise, any Follow/Undo/Accept activity
would trigger the synchronization mechanism even if processing the activity
itself would be enough to re-introduce synchronization)
* Change how ActivityPub::SynchronizeFollowersService handles follow requests
If the remote lists a local follower which we only know has sent a follow
request, consider the follow request as accepted instead of sending an Undo.
* Integrate review feeback
- rename X-AS-Collection-Synchronization to Collection-Synchronization
- various minor refactoring and code style changes
* Only select required fields when computing followers_hash
* Use actor URI rather than webfinger domain in synchronization endpoint
* Change hash computation to be a XOR of individual hashes
Makes it much easier to be memory-efficient, and avoid sorting discrepancy issues.
* Marginally improve followers_hash computation speed
* Further improve hash computation performances by using pluck_each
2020-10-21 18:04:09 +02:00
|
|
|
|
2021-08-11 17:48:42 +02:00
|
|
|
before do
|
2023-06-14 16:44:37 +02:00
|
|
|
me.follow!(remote_alice)
|
2021-08-11 17:48:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct hash for local users' do
|
2023-06-14 16:44:37 +02:00
|
|
|
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
2021-08-11 17:48:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'invalidates cache as needed when removing or adding followers' do
|
2023-06-14 16:44:37 +02:00
|
|
|
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
|
|
|
me.unfollow!(remote_alice)
|
|
|
|
expect(remote_alice.local_followers_hash).to eq '0000000000000000000000000000000000000000000000000000000000000000'
|
|
|
|
me.follow!(remote_alice)
|
|
|
|
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
Add follower synchronization mechanism (#14510)
* Add support for followers synchronization on the receiving end
Check the `collectionSynchronization` attribute on `Create` and `Announce`
activities and synchronize followers from provided collection if possible.
* Add tests for followers synchronization on the receiving end
* Add support for follower synchronization on the sender's end
* Add tests for the sending end
* Switch from AS attributes to HTTP header
Replace the custom `collectionSynchronization` ActivityStreams attribute by
an HTTP header (`X-AS-Collection-Synchronization`) with the same syntax as
the `Signature` header and the following fields:
- `collectionId` to specify which collection to synchronize
- `digest` for the SHA256 hex-digest of the list of followers known on the
receiving instance (where “receiving instance” is determined by accounts
sharing the same host name for their ActivityPub actor `id`)
- `url` of a collection that should be fetched by the instance actor
Internally, move away from the webfinger-based `domain` attribute and use
account `uri` prefix to group accounts.
* Add environment variable to disable followers synchronization
Since the whole mechanism relies on some new preconditions that, in some
extremely rare cases, might not be met, add an environment variable
(DISABLE_FOLLOWERS_SYNCHRONIZATION) to disable the mechanism altogether and
avoid followers being incorrectly removed.
The current conditions are:
1. all managed accounts' actor `id` and inbox URL have the same URI scheme and
netloc.
2. all accounts whose actor `id` or inbox URL share the same URI scheme and
netloc as a managed account must be managed by the same Mastodon instance
as well.
As far as Mastodon is concerned, breaking those preconditions require extensive
configuration changes in the reverse proxy and might also cause other issues.
Therefore, this environment variable provides a way out for people with highly
unusual configurations, and can be safely ignored for the overwhelming majority
of Mastodon administrators.
* Only set follower synchronization header on non-public statuses
This is to avoid unnecessary computations and allow Follow-related
activities to be handled by the usual codepath instead of going through
the synchronization mechanism (otherwise, any Follow/Undo/Accept activity
would trigger the synchronization mechanism even if processing the activity
itself would be enough to re-introduce synchronization)
* Change how ActivityPub::SynchronizeFollowersService handles follow requests
If the remote lists a local follower which we only know has sent a follow
request, consider the follow request as accepted instead of sending an Undo.
* Integrate review feeback
- rename X-AS-Collection-Synchronization to Collection-Synchronization
- various minor refactoring and code style changes
* Only select required fields when computing followers_hash
* Use actor URI rather than webfinger domain in synchronization endpoint
* Change hash computation to be a XOR of individual hashes
Makes it much easier to be memory-efficient, and avoid sorting discrepancy issues.
* Marginally improve followers_hash computation speed
* Further improve hash computation performances by using pluck_each
2020-10-21 18:04:09 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-15 03:56:41 +01:00
|
|
|
describe 'muting an account' do
|
|
|
|
let(:me) { Fabricate(:account, username: 'Me') }
|
|
|
|
let(:you) { Fabricate(:account, username: 'You') }
|
|
|
|
|
|
|
|
context 'with the notifications option unspecified' do
|
|
|
|
before do
|
|
|
|
me.mute!(you)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults to muting notifications' do
|
|
|
|
expect(me.muting_notifications?(you)).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with the notifications option set to false' do
|
|
|
|
before do
|
|
|
|
me.mute!(you, notifications: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not mute notifications' do
|
|
|
|
expect(me.muting_notifications?(you)).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with the notifications option set to true' do
|
|
|
|
before do
|
|
|
|
me.mute!(you, notifications: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does mute notifications' do
|
|
|
|
expect(me.muting_notifications?(you)).to be true
|
2017-09-14 03:44:38 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-11-11 03:11:10 +01:00
|
|
|
|
|
|
|
describe 'ignoring reblogs from an account' do
|
2023-11-08 16:42:30 +01:00
|
|
|
let!(:me) { Fabricate(:account, username: 'Me') }
|
|
|
|
let!(:you) { Fabricate(:account, username: 'You') }
|
2017-11-11 03:11:10 +01:00
|
|
|
|
|
|
|
context 'with the reblogs option unspecified' do
|
|
|
|
before do
|
2023-11-08 16:42:30 +01:00
|
|
|
me.follow!(you)
|
2017-11-11 03:11:10 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults to showing reblogs' do
|
2023-11-08 16:42:30 +01:00
|
|
|
expect(me.muting_reblogs?(you)).to be(false)
|
2017-11-11 03:11:10 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with the reblogs option set to false' do
|
|
|
|
before do
|
2023-11-08 16:42:30 +01:00
|
|
|
me.follow!(you, reblogs: false)
|
2017-11-11 03:11:10 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does mute reblogs' do
|
2023-11-08 16:42:30 +01:00
|
|
|
expect(me.muting_reblogs?(you)).to be(true)
|
2017-11-11 03:11:10 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with the reblogs option set to true' do
|
|
|
|
before do
|
2023-11-08 16:42:30 +01:00
|
|
|
me.follow!(you, reblogs: true)
|
2017-11-11 03:11:10 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not mute reblogs' do
|
2023-11-08 16:42:30 +01:00
|
|
|
expect(me.muting_reblogs?(you)).to be(false)
|
2017-11-15 03:56:41 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-05-02 14:40:36 +02:00
|
|
|
|
|
|
|
describe '#lists_for_local_distribution' do
|
2023-05-03 19:17:40 +02:00
|
|
|
let(:account) { Fabricate(:user, current_sign_in_at: Time.now.utc).account }
|
2023-05-02 14:40:36 +02:00
|
|
|
let!(:inactive_follower_user) { Fabricate(:user, current_sign_in_at: 5.years.ago) }
|
|
|
|
let!(:follower_user) { Fabricate(:user, current_sign_in_at: Time.now.utc) }
|
|
|
|
let!(:follow_request_user) { Fabricate(:user, current_sign_in_at: Time.now.utc) }
|
|
|
|
|
|
|
|
let!(:inactive_follower_list) { Fabricate(:list, account: inactive_follower_user.account) }
|
|
|
|
let!(:follower_list) { Fabricate(:list, account: follower_user.account) }
|
|
|
|
let!(:follow_request_list) { Fabricate(:list, account: follow_request_user.account) }
|
|
|
|
|
2023-05-03 19:17:40 +02:00
|
|
|
let!(:self_list) { Fabricate(:list, account: account) }
|
|
|
|
|
2023-05-02 14:40:36 +02:00
|
|
|
before do
|
|
|
|
inactive_follower_user.account.follow!(account)
|
|
|
|
follower_user.account.follow!(account)
|
|
|
|
follow_request_user.account.follow_requests.create!(target_account: account)
|
|
|
|
|
|
|
|
inactive_follower_list.accounts << account
|
|
|
|
follower_list.accounts << account
|
|
|
|
follow_request_list.accounts << account
|
2023-05-03 19:17:40 +02:00
|
|
|
self_list.accounts << account
|
2023-05-02 14:40:36 +02:00
|
|
|
end
|
|
|
|
|
2023-05-03 19:17:40 +02:00
|
|
|
it 'includes only the list from the active follower and from oneself' do
|
|
|
|
expect(account.lists_for_local_distribution.to_a).to contain_exactly(follower_list, self_list)
|
2023-05-02 14:40:36 +02:00
|
|
|
end
|
|
|
|
end
|
2017-11-15 03:56:41 +01:00
|
|
|
end
|