Skip to content

Commit 2b97b5c

Browse files
committed
Fix show_reblogs not being preserved for moved account's followers
1 parent 668ecc4 commit 2b97b5c

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

app/workers/unfollow_follow_worker.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ def perform(follower_account_id, old_target_account_id, new_target_account_id, b
1010
old_target_account = Account.find(old_target_account_id)
1111
new_target_account = Account.find(new_target_account_id)
1212

13-
FollowService.new.call(follower_account, new_target_account, bypass_locked: bypass_locked)
13+
follow = follower_account.active_relationships.find_by(target_account: old_target_account)
14+
reblogs = follow&.show_reblogs?
15+
16+
FollowService.new.call(follower_account, new_target_account, reblogs: reblogs, bypass_locked: bypass_locked)
1417
UnfollowService.new.call(follower_account, old_target_account, skip_unmerge: true)
1518
rescue ActiveRecord::RecordNotFound, Mastodon::NotPermittedError
1619
true
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
describe UnfollowFollowWorker do
6+
let(:local_follower) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
7+
let(:source_account) { Fabricate(:account) }
8+
let(:target_account) { Fabricate(:account) }
9+
let(:show_reblogs) { true }
10+
11+
subject { described_class.new }
12+
13+
before do
14+
local_follower.follow!(source_account, reblogs: show_reblogs)
15+
end
16+
17+
context 'when show_reblogs is true' do
18+
let(:show_reblogs) { true }
19+
20+
describe 'perform' do
21+
it 'unfollows source account and follows target account' do
22+
subject.perform(local_follower.id, source_account.id, target_account.id)
23+
expect(local_follower.following?(source_account)).to be false
24+
expect(local_follower.following?(target_account)).to be true
25+
end
26+
27+
it 'preserves show_reblogs' do
28+
subject.perform(local_follower.id, source_account.id, target_account.id)
29+
expect(Follow.find_by(account: local_follower, target_account: target_account).show_reblogs?).to be show_reblogs
30+
end
31+
end
32+
end
33+
34+
context 'when show_reblogs is false' do
35+
let(:show_reblogs) { false }
36+
37+
describe 'perform' do
38+
it 'unfollows source account and follows target account' do
39+
subject.perform(local_follower.id, source_account.id, target_account.id)
40+
expect(local_follower.following?(source_account)).to be false
41+
expect(local_follower.following?(target_account)).to be true
42+
end
43+
44+
it 'preserves show_reblogs' do
45+
subject.perform(local_follower.id, source_account.id, target_account.id)
46+
expect(Follow.find_by(account: local_follower, target_account: target_account).show_reblogs?).to be show_reblogs
47+
end
48+
end
49+
end
50+
end

0 commit comments

Comments
 (0)