Add ability to filter followed accounts' posts by language (#19095)

This commit is contained in:
Eugen Rochko 2022-09-20 23:51:21 +02:00 committed by GitHub
parent 882e54c786
commit 50948b46aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 298 additions and 39 deletions

View file

@ -145,6 +145,17 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
expect(json[:showing_reblogs]).to be false
expect(json[:notifying]).to be true
end
it 'changes languages option' do
post :follow, params: { id: other_account.id, languages: %w(en es) }
json = body_as_json
expect(json[:following]).to be true
expect(json[:showing_reblogs]).to be false
expect(json[:notifying]).to be false
expect(json[:languages]).to match_array %w(en es)
end
end
end

View file

@ -11,7 +11,7 @@ describe Settings::Exports::FollowingAccountsController do
sign_in user, scope: :user
get :index, format: :csv
expect(response.body).to eq "Account address,Show boosts\nusername@domain,true\n"
expect(response.body).to eq "Account address,Show boosts,Notify on new posts,Languages\nusername@domain,true,false,\n"
end
end
end

View file

@ -127,6 +127,18 @@ RSpec.describe FeedManager do
reblog = Fabricate(:status, reblog: status, account: jeff)
expect(FeedManager.instance.filter?(:home, reblog, alice)).to be true
end
it 'returns true for German post when follow is set to English only' do
alice.follow!(bob, languages: %w(en))
status = Fabricate(:status, text: 'Hallo Welt', account: bob, language: 'de')
expect(FeedManager.instance.filter?(:home, status, alice)).to be true
end
it 'returns false for German post when follow is set to German' do
alice.follow!(bob, languages: %w(de))
status = Fabricate(:status, text: 'Hallo Welt', account: bob, language: 'de')
expect(FeedManager.instance.filter?(:home, status, alice)).to be false
end
end
context 'for mentions feed' do

View file

@ -14,7 +14,7 @@ describe AccountInteractions do
context 'account with Follow' do
it 'returns { target_account_id => true }' do
Fabricate(:follow, account: account, target_account: target_account)
is_expected.to eq(target_account_id => { reblogs: true, notify: false })
is_expected.to eq(target_account_id => { reblogs: true, notify: false, languages: nil })
end
end

View file

@ -35,8 +35,8 @@ describe Export do
results = export.strip.split("\n")
expect(results.size).to eq 3
expect(results.first).to eq 'Account address,Show boosts'
expect(results.second).to eq 'one@local.host,true'
expect(results.first).to eq 'Account address,Show boosts,Notify on new posts,Languages'
expect(results.second).to eq 'one@local.host,true,false,'
end
end

View file

@ -7,7 +7,7 @@ RSpec.describe FollowRequest, type: :model do
let(:target_account) { Fabricate(:account) }
it 'calls Account#follow!, MergeWorker.perform_async, and #destroy!' do
expect(account).to receive(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri, bypass_limit: true)
expect(account).to receive(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri, languages: nil, bypass_limit: true)
expect(MergeWorker).to receive(:perform_async).with(target_account.id, account.id)
expect(follow_request).to receive(:destroy!)
follow_request.authorize!

View file

@ -121,6 +121,19 @@ RSpec.describe FollowService, type: :service do
expect(sender.muting_reblogs?(bob)).to be false
end
end
describe 'already followed account, changing languages' do
let(:bob) { Fabricate(:account, username: 'bob') }
before do
sender.follow!(bob)
subject.call(sender, bob, languages: %w(en es))
end
it 'changes languages' do
expect(Follow.find_by(account: sender, target_account: bob)&.languages).to match_array %w(en es)
end
end
end
context 'remote ActivityPub account' do

View file

@ -23,8 +23,8 @@ describe RefollowWorker do
result = subject.perform(account.id)
expect(result).to be_nil
expect(service).to have_received(:call).with(alice, account, reblogs: true, notify: false, bypass_limit: true)
expect(service).to have_received(:call).with(bob, account, reblogs: false, notify: false, bypass_limit: true)
expect(service).to have_received(:call).with(alice, account, reblogs: true, notify: false, languages: nil, bypass_limit: true)
expect(service).to have_received(:call).with(bob, account, reblogs: false, notify: false, languages: nil, bypass_limit: true)
end
end
end