2017-11-15 02:56:41 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe AccountInteractions do
|
2017-11-19 03:16:14 +00:00
|
|
|
let(:account) { Fabricate(:account, username: 'account') }
|
|
|
|
let(:account_id) { account.id }
|
|
|
|
let(:account_ids) { [account_id] }
|
|
|
|
let(:target_account) { Fabricate(:account, username: 'target') }
|
|
|
|
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) }
|
|
|
|
|
|
|
|
context 'account with Follow' do
|
2017-11-19 08:56:45 +00:00
|
|
|
it 'returns { target_account_id => { reblogs: true } }' do
|
2017-11-19 03:16:14 +00:00
|
|
|
Fabricate(:follow, account: account, target_account: target_account)
|
2022-09-20 21:51:21 +00:00
|
|
|
is_expected.to eq(target_account_id => { reblogs: true, notify: false, languages: nil })
|
2017-11-19 08:56:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'account with Follow but with reblogs disabled' do
|
|
|
|
it 'returns { target_account_id => { reblogs: false } }' do
|
|
|
|
Fabricate(:follow, account: account, target_account: target_account, show_reblogs: false)
|
2022-10-02 15:33:37 +00:00
|
|
|
is_expected.to eq(target_account_id => { reblogs: false, notify: false, languages: nil })
|
2017-11-19 03:16:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'account without Follow' do
|
|
|
|
it 'returns {}' do
|
|
|
|
is_expected.to eq({})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.followed_by_map' do
|
|
|
|
subject { Account.followed_by_map(target_account_ids, account_id) }
|
|
|
|
|
|
|
|
context 'account with Follow' do
|
|
|
|
it 'returns { target_account_id => true }' do
|
|
|
|
Fabricate(:follow, account: target_account, target_account: account)
|
|
|
|
is_expected.to eq(target_account_id => true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'account without Follow' do
|
|
|
|
it 'returns {}' do
|
|
|
|
is_expected.to eq({})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.blocking_map' do
|
|
|
|
subject { Account.blocking_map(target_account_ids, account_id) }
|
|
|
|
|
|
|
|
context 'account with Block' do
|
|
|
|
it 'returns { target_account_id => true }' do
|
|
|
|
Fabricate(:block, account: account, target_account: target_account)
|
|
|
|
is_expected.to eq(target_account_id => true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'account without Block' do
|
|
|
|
it 'returns {}' do
|
|
|
|
is_expected.to eq({})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.muting_map' do
|
|
|
|
subject { Account.muting_map(target_account_ids, account_id) }
|
|
|
|
|
|
|
|
context 'account with Mute' do
|
|
|
|
before do
|
|
|
|
Fabricate(:mute, target_account: target_account, account: account, hide_notifications: hide)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'if Mute#hide_notifications?' do
|
|
|
|
let(:hide) { true }
|
|
|
|
|
|
|
|
it 'returns { target_account_id => { notifications: true } }' do
|
|
|
|
is_expected.to eq(target_account_id => { notifications: true })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unless Mute#hide_notifications?' do
|
|
|
|
let(:hide) { false }
|
|
|
|
|
|
|
|
it 'returns { target_account_id => { notifications: false } }' do
|
|
|
|
is_expected.to eq(target_account_id => { notifications: false })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'account without Mute' do
|
|
|
|
it 'returns {}' do
|
|
|
|
is_expected.to eq({})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#follow!' do
|
|
|
|
it 'creates and returns Follow' do
|
|
|
|
expect do
|
|
|
|
expect(account.follow!(target_account)).to be_kind_of Follow
|
|
|
|
end.to change { account.following.count }.by 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#block' do
|
|
|
|
it 'creates and returns Block' do
|
|
|
|
expect do
|
|
|
|
expect(account.block!(target_account)).to be_kind_of Block
|
|
|
|
end.to change { account.block_relationships.count }.by 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#mute!' do
|
2018-05-02 14:14:51 +00:00
|
|
|
subject { account.mute!(target_account, notifications: arg_notifications) }
|
|
|
|
|
2017-11-19 03:16:14 +00:00
|
|
|
context 'Mute does not exist yet' do
|
|
|
|
context 'arg :notifications is nil' do
|
|
|
|
let(:arg_notifications) { nil }
|
|
|
|
|
2018-05-02 14:14:51 +00:00
|
|
|
it 'creates Mute, and returns Mute' do
|
2017-11-19 03:16:14 +00:00
|
|
|
expect do
|
2018-05-02 14:14:51 +00:00
|
|
|
expect(subject).to be_kind_of Mute
|
2017-11-19 03:16:14 +00:00
|
|
|
end.to change { account.mute_relationships.count }.by 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'arg :notifications is false' do
|
|
|
|
let(:arg_notifications) { false }
|
|
|
|
|
2018-05-02 14:14:51 +00:00
|
|
|
it 'creates Mute, and returns Mute' do
|
2017-11-19 03:16:14 +00:00
|
|
|
expect do
|
2018-05-02 14:14:51 +00:00
|
|
|
expect(subject).to be_kind_of Mute
|
2017-11-19 03:16:14 +00:00
|
|
|
end.to change { account.mute_relationships.count }.by 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'arg :notifications is true' do
|
|
|
|
let(:arg_notifications) { true }
|
|
|
|
|
2018-05-02 14:14:51 +00:00
|
|
|
it 'creates Mute, and returns Mute' do
|
2017-11-19 03:16:14 +00:00
|
|
|
expect do
|
2018-05-02 14:14:51 +00:00
|
|
|
expect(subject).to be_kind_of Mute
|
2017-11-19 03:16:14 +00:00
|
|
|
end.to change { account.mute_relationships.count }.by 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'Mute already exists' do
|
|
|
|
before do
|
|
|
|
account.mute_relationships << mute
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:mute) do
|
|
|
|
Fabricate(:mute,
|
|
|
|
account: account,
|
|
|
|
target_account: target_account,
|
|
|
|
hide_notifications: hide_notifications)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'mute.hide_notifications is true' do
|
|
|
|
let(:hide_notifications) { true }
|
|
|
|
|
|
|
|
context 'arg :notifications is nil' do
|
|
|
|
let(:arg_notifications) { nil }
|
|
|
|
|
2018-05-02 14:14:51 +00:00
|
|
|
it 'returns Mute without updating mute.hide_notifications' do
|
2017-11-19 03:16:14 +00:00
|
|
|
expect do
|
2018-05-02 14:14:51 +00:00
|
|
|
expect(subject).to be_kind_of Mute
|
|
|
|
end.not_to change { mute.reload.hide_notifications? }.from(true)
|
2017-11-19 03:16:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'arg :notifications is false' do
|
|
|
|
let(:arg_notifications) { false }
|
|
|
|
|
2018-05-02 14:14:51 +00:00
|
|
|
it 'returns Mute, and updates mute.hide_notifications false' do
|
2017-11-19 03:16:14 +00:00
|
|
|
expect do
|
2018-05-02 14:14:51 +00:00
|
|
|
expect(subject).to be_kind_of Mute
|
|
|
|
end.to change { mute.reload.hide_notifications? }.from(true).to(false)
|
2017-11-19 03:16:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'arg :notifications is true' do
|
|
|
|
let(:arg_notifications) { true }
|
|
|
|
|
2018-05-02 14:14:51 +00:00
|
|
|
it 'returns Mute without updating mute.hide_notifications' do
|
2017-11-19 03:16:14 +00:00
|
|
|
expect do
|
2018-05-02 14:14:51 +00:00
|
|
|
expect(subject).to be_kind_of Mute
|
|
|
|
end.not_to change { mute.reload.hide_notifications? }.from(true)
|
2017-11-19 03:16:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'mute.hide_notifications is false' do
|
|
|
|
let(:hide_notifications) { false }
|
|
|
|
|
|
|
|
context 'arg :notifications is nil' do
|
|
|
|
let(:arg_notifications) { nil }
|
|
|
|
|
2018-05-02 14:14:51 +00:00
|
|
|
it 'returns Mute, and updates mute.hide_notifications true' do
|
2017-11-19 03:16:14 +00:00
|
|
|
expect do
|
2018-05-02 14:14:51 +00:00
|
|
|
expect(subject).to be_kind_of Mute
|
|
|
|
end.to change { mute.reload.hide_notifications? }.from(false).to(true)
|
2017-11-19 03:16:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'arg :notifications is false' do
|
|
|
|
let(:arg_notifications) { false }
|
|
|
|
|
2018-05-02 14:14:51 +00:00
|
|
|
it 'returns Mute without updating mute.hide_notifications' do
|
2017-11-19 03:16:14 +00:00
|
|
|
expect do
|
2018-05-02 14:14:51 +00:00
|
|
|
expect(subject).to be_kind_of Mute
|
|
|
|
end.not_to change { mute.reload.hide_notifications? }.from(false)
|
2017-11-19 03:16:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'arg :notifications is true' do
|
|
|
|
let(:arg_notifications) { true }
|
|
|
|
|
2018-05-02 14:14:51 +00:00
|
|
|
it 'returns Mute, and updates mute.hide_notifications true' do
|
2017-11-19 03:16:14 +00:00
|
|
|
expect do
|
2018-05-02 14:14:51 +00:00
|
|
|
expect(subject).to be_kind_of Mute
|
|
|
|
end.to change { mute.reload.hide_notifications? }.from(false).to(true)
|
2017-11-19 03:16:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#mute_conversation!' do
|
|
|
|
let(:conversation) { Fabricate(:conversation) }
|
|
|
|
|
|
|
|
subject { account.mute_conversation!(conversation) }
|
|
|
|
|
|
|
|
it 'creates and returns ConversationMute' do
|
|
|
|
expect do
|
|
|
|
is_expected.to be_kind_of ConversationMute
|
|
|
|
end.to change { account.conversation_mutes.count }.by 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#block_domain!' do
|
2019-02-03 02:59:51 +00:00
|
|
|
let(:domain) { 'example.com' }
|
2017-11-19 03:16:14 +00:00
|
|
|
|
2019-02-03 02:59:51 +00:00
|
|
|
subject { account.block_domain!(domain) }
|
2017-11-19 03:16:14 +00:00
|
|
|
|
|
|
|
it 'creates and returns AccountDomainBlock' do
|
|
|
|
expect do
|
|
|
|
is_expected.to be_kind_of AccountDomainBlock
|
|
|
|
end.to change { account.domain_blocks.count }.by 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#unfollow!' do
|
|
|
|
subject { account.unfollow!(target_account) }
|
|
|
|
|
|
|
|
context 'following target_account' do
|
|
|
|
it 'returns destroyed Follow' do
|
|
|
|
account.active_relationships.create(target_account: target_account)
|
|
|
|
is_expected.to be_kind_of Follow
|
|
|
|
expect(subject).to be_destroyed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'not following target_account' do
|
|
|
|
it 'returns nil' do
|
|
|
|
is_expected.to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#unblock!' do
|
|
|
|
subject { account.unblock!(target_account) }
|
|
|
|
|
|
|
|
context 'blocking target_account' do
|
|
|
|
it 'returns destroyed Block' do
|
|
|
|
account.block_relationships.create(target_account: target_account)
|
|
|
|
is_expected.to be_kind_of Block
|
|
|
|
expect(subject).to be_destroyed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'not blocking target_account' do
|
|
|
|
it 'returns nil' do
|
|
|
|
is_expected.to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#unmute!' do
|
|
|
|
subject { account.unmute!(target_account) }
|
|
|
|
|
|
|
|
context 'muting target_account' do
|
|
|
|
it 'returns destroyed Mute' do
|
|
|
|
account.mute_relationships.create(target_account: target_account)
|
|
|
|
is_expected.to be_kind_of Mute
|
|
|
|
expect(subject).to be_destroyed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'not muting target_account' do
|
|
|
|
it 'returns nil' do
|
|
|
|
is_expected.to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#unmute_conversation!' do
|
|
|
|
let(:conversation) { Fabricate(:conversation) }
|
|
|
|
|
|
|
|
subject { account.unmute_conversation!(conversation) }
|
|
|
|
|
|
|
|
context 'muting the conversation' do
|
|
|
|
it 'returns destroyed ConversationMute' do
|
|
|
|
account.conversation_mutes.create(conversation: conversation)
|
|
|
|
is_expected.to be_kind_of ConversationMute
|
|
|
|
expect(subject).to be_destroyed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'not muting the conversation' do
|
|
|
|
it 'returns nil' do
|
|
|
|
is_expected.to be nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#unblock_domain!' do
|
|
|
|
let(:domain) { 'example.com' }
|
|
|
|
|
|
|
|
subject { account.unblock_domain!(domain) }
|
|
|
|
|
|
|
|
context 'blocking the domain' do
|
|
|
|
it 'returns destroyed AccountDomainBlock' do
|
|
|
|
account_domain_block = Fabricate(:account_domain_block, domain: domain)
|
|
|
|
account.domain_blocks << account_domain_block
|
|
|
|
is_expected.to be_kind_of AccountDomainBlock
|
|
|
|
expect(subject).to be_destroyed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unblocking the domain' do
|
|
|
|
it 'returns nil' do
|
|
|
|
is_expected.to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#following?' do
|
|
|
|
subject { account.following?(target_account) }
|
|
|
|
|
|
|
|
context 'following target_account' do
|
|
|
|
it 'returns true' do
|
|
|
|
account.active_relationships.create(target_account: target_account)
|
|
|
|
is_expected.to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'not following target_account' do
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-10-18 10:02:35 +00:00
|
|
|
describe '#followed_by?' do
|
|
|
|
subject { account.followed_by?(target_account) }
|
|
|
|
|
|
|
|
context 'followed by target_account' do
|
|
|
|
it 'returns true' do
|
|
|
|
account.passive_relationships.create(account: target_account)
|
|
|
|
is_expected.to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'not followed by target_account' do
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-19 03:16:14 +00:00
|
|
|
describe '#blocking?' do
|
|
|
|
subject { account.blocking?(target_account) }
|
|
|
|
|
|
|
|
context 'blocking target_account' do
|
|
|
|
it 'returns true' do
|
|
|
|
account.block_relationships.create(target_account: target_account)
|
|
|
|
is_expected.to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'not blocking target_account' do
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#domain_blocking?' do
|
|
|
|
let(:domain) { 'example.com' }
|
|
|
|
|
|
|
|
subject { account.domain_blocking?(domain) }
|
|
|
|
|
|
|
|
context 'blocking the domain' do
|
|
|
|
it' returns true' do
|
|
|
|
account_domain_block = Fabricate(:account_domain_block, domain: domain)
|
|
|
|
account.domain_blocks << account_domain_block
|
|
|
|
is_expected.to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'not blocking the domain' do
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#muting?' do
|
|
|
|
subject { account.muting?(target_account) }
|
|
|
|
|
|
|
|
context 'muting target_account' do
|
|
|
|
it 'returns true' do
|
|
|
|
mute = Fabricate(:mute, account: account, target_account: target_account)
|
|
|
|
account.mute_relationships << mute
|
|
|
|
is_expected.to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'not muting target_account' do
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#muting_conversation?' do
|
|
|
|
let(:conversation) { Fabricate(:conversation) }
|
|
|
|
|
|
|
|
subject { account.muting_conversation?(conversation) }
|
|
|
|
|
|
|
|
context 'muting the conversation' do
|
|
|
|
it 'returns true' do
|
|
|
|
account.conversation_mutes.create(conversation: conversation)
|
|
|
|
is_expected.to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'not muting the conversation' do
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#muting_notifications?' do
|
|
|
|
before do
|
|
|
|
mute = Fabricate(:mute, target_account: target_account, account: account, hide_notifications: hide)
|
|
|
|
account.mute_relationships << mute
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { account.muting_notifications?(target_account) }
|
|
|
|
|
|
|
|
context 'muting notifications of target_account' do
|
|
|
|
let(:hide) { true }
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
is_expected.to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'not muting notifications of target_account' do
|
|
|
|
let(:hide) { false }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#requested?' do
|
|
|
|
subject { account.requested?(target_account) }
|
|
|
|
|
|
|
|
context 'requested by target_account' do
|
|
|
|
it 'returns true' do
|
|
|
|
Fabricate(:follow_request, account: account, target_account: target_account)
|
|
|
|
is_expected.to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'not requested by target_account' do
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#favourited?' do
|
|
|
|
let(:status) { Fabricate(:status, account: account, favourites: favourites) }
|
|
|
|
|
|
|
|
subject { account.favourited?(status) }
|
|
|
|
|
|
|
|
context 'favorited' do
|
|
|
|
let(:favourites) { [Fabricate(:favourite, account: account)] }
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
is_expected.to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'not favorited' do
|
|
|
|
let(:favourites) { [] }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#reblogged?' do
|
|
|
|
let(:status) { Fabricate(:status, account: account, reblogs: reblogs) }
|
|
|
|
|
|
|
|
subject { account.reblogged?(status) }
|
|
|
|
|
|
|
|
context 'reblogged' do
|
|
|
|
let(:reblogs) { [Fabricate(:status, account: account)] }
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
is_expected.to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'not reblogged' do
|
|
|
|
let(:reblogs) { [] }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#pinned?' do
|
|
|
|
let(:status) { Fabricate(:status, account: account) }
|
|
|
|
|
|
|
|
subject { account.pinned?(status) }
|
|
|
|
|
|
|
|
context 'pinned' do
|
|
|
|
it 'returns true' do
|
|
|
|
Fabricate(:status_pin, account: account, status: status)
|
|
|
|
is_expected.to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'not pinned' do
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-11 15:48:42 +00: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 16:04:09 +00:00
|
|
|
let(:me) { Fabricate(:account, username: 'Me') }
|
|
|
|
let(:remote_1) { Fabricate(:account, username: 'alice', domain: 'example.org', uri: 'https://example.org/users/alice') }
|
|
|
|
let(:remote_2) { Fabricate(:account, username: 'bob', domain: 'example.org', uri: 'https://example.org/users/bob') }
|
2021-08-11 15:48:42 +00:00
|
|
|
let(:remote_3) { Fabricate(:account, username: 'instance-actor', domain: 'example.org', uri: 'https://example.org') }
|
|
|
|
let(:remote_4) { 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 16:04:09 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
remote_1.follow!(me)
|
|
|
|
remote_2.follow!(me)
|
|
|
|
remote_3.follow!(me)
|
2021-08-11 15:48:42 +00:00
|
|
|
remote_4.follow!(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 16:04:09 +00:00
|
|
|
me.follow!(remote_1)
|
|
|
|
end
|
|
|
|
|
2021-08-11 15:48:42 +00: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 16:04:09 +00:00
|
|
|
|
2021-08-11 15:48:42 +00:00
|
|
|
it 'invalidates cache as needed when removing or adding followers' do
|
|
|
|
expect(me.remote_followers_hash('https://example.org/')).to eq '20aecbe774b3d61c25094370baf370012b9271c5b172ecedb05caff8d79ef0c7'
|
|
|
|
remote_3.unfollow!(me)
|
|
|
|
expect(me.remote_followers_hash('https://example.org/')).to eq '707962e297b7bd94468a21bc8e506a1bcea607a9142cd64e27c9b106b2a5f6ec'
|
|
|
|
remote_1.unfollow!(me)
|
|
|
|
expect(me.remote_followers_hash('https://example.org/')).to eq '241b00794ce9b46aa864f3220afadef128318da2659782985bac5ed5bd436bff'
|
|
|
|
remote_1.follow!(me)
|
|
|
|
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 16:04:09 +00:00
|
|
|
end
|
2021-08-11 15:48:42 +00: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 16:04:09 +00:00
|
|
|
|
2021-08-11 15:48:42 +00:00
|
|
|
describe '#local_followers_hash' do
|
|
|
|
let(:me) { Fabricate(:account, username: 'Me') }
|
|
|
|
let(:remote_1) { 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 16:04:09 +00:00
|
|
|
|
2021-08-11 15:48:42 +00:00
|
|
|
before do
|
|
|
|
me.follow!(remote_1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct hash for local users' do
|
|
|
|
expect(remote_1.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'invalidates cache as needed when removing or adding followers' do
|
|
|
|
expect(remote_1.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
|
|
|
me.unfollow!(remote_1)
|
|
|
|
expect(remote_1.local_followers_hash).to eq '0000000000000000000000000000000000000000000000000000000000000000'
|
|
|
|
me.follow!(remote_1)
|
|
|
|
expect(remote_1.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 16:04:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-15 02:56:41 +00: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 01:44:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-11-11 02:11:10 +00:00
|
|
|
|
|
|
|
describe 'ignoring reblogs from an account' do
|
|
|
|
before do
|
|
|
|
@me = Fabricate(:account, username: 'Me')
|
|
|
|
@you = Fabricate(:account, username: 'You')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with the reblogs option unspecified' do
|
|
|
|
before do
|
|
|
|
@me.follow!(@you)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults to showing reblogs' do
|
|
|
|
expect(@me.muting_reblogs?(@you)).to be(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with the reblogs option set to false' do
|
|
|
|
before do
|
|
|
|
@me.follow!(@you, reblogs: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does mute reblogs' do
|
|
|
|
expect(@me.muting_reblogs?(@you)).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with the reblogs option set to true' do
|
|
|
|
before do
|
|
|
|
@me.follow!(@you, reblogs: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not mute reblogs' do
|
|
|
|
expect(@me.muting_reblogs?(@you)).to be(false)
|
2017-11-15 02:56:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
Allow hiding of reblogs from followed users (#5762)
* Allow hiding of reblogs from followed users
This adds a new entry to the account menu to allow users to hide
future reblogs from a user (and then if they've done that, to show
future reblogs instead).
This does not remove or add historical reblogs from/to the user's
timeline; it only affects new statuses.
The API for this operates by sending a "reblogs" key to the follow
endpoint. If this is sent when starting a new follow, it will be
respected from the beginning of the follow relationship (even if
the follow request must be approved by the followee). If this is
sent when a follow relationship already exists, it will simply
update the existing follow relationship. As with the notification
muting, this will now return an object ({reblogs: [true|false]}) or
false for each follow relationship when requesting relationship
information for an account. This should cause few issues due to an
object being truthy in many languages, but some modifications may
need to be made in pickier languages.
Database changes: adds a show_reblogs column (default true,
non-nullable) to the follows and follow_requests tables. Because
these are non-nullable, we use the existing MigrationHelpers to
perform this change without locking those tables, although the
tables are likely to be small anyway.
Tests included.
See also <https://github.com/glitch-soc/mastodon/pull/212>.
* Rubocop fixes
* Code review changes
* Test fixes
This patchset closes #648 and resolves #3271.
* Rubocop fix
* Revert reblogs defaulting in argument, fix tests
It turns out we needed this for the same reason we needed it in muting:
if nil gets passed in somehow (most usually by an API client not passing
any value), we need to detect and handle it.
We could specify a default in the parameter and then also catch nil, but
there's no great reason to duplicate the default value.
2017-11-28 14:00:35 +00:00
|
|
|
|
|
|
|
describe 'ignoring reblogs from an account' do
|
|
|
|
before do
|
|
|
|
@me = Fabricate(:account, username: 'Me')
|
|
|
|
@you = Fabricate(:account, username: 'You')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with the reblogs option unspecified' do
|
|
|
|
before do
|
|
|
|
@me.follow!(@you)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults to showing reblogs' do
|
|
|
|
expect(@me.muting_reblogs?(@you)).to be(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with the reblogs option set to false' do
|
|
|
|
before do
|
|
|
|
@me.follow!(@you, reblogs: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does mute reblogs' do
|
|
|
|
expect(@me.muting_reblogs?(@you)).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with the reblogs option set to true' do
|
|
|
|
before do
|
|
|
|
@me.follow!(@you, reblogs: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not mute reblogs' do
|
|
|
|
expect(@me.muting_reblogs?(@you)).to be(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-11-15 02:56:41 +00:00
|
|
|
end
|