mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 17:31:12 +00:00
Add with_list_account
scope to List
model (#35539)
This commit is contained in:
parent
018e5e303f
commit
7cd3738c19
|
@ -37,7 +37,7 @@ class FollowRequest < ApplicationRecord
|
|||
if account.local?
|
||||
ListAccount.where(follow_request: self).update_all(follow_request_id: nil, follow_id: follow.id)
|
||||
MergeWorker.perform_async(target_account.id, account.id, 'home')
|
||||
MergeWorker.push_bulk(List.where(account: account).joins(:list_accounts).where(list_accounts: { account_id: target_account.id }).pluck(:id)) do |list_id|
|
||||
MergeWorker.push_bulk(account.owned_lists.with_list_account(target_account).pluck(:id)) do |list_id|
|
||||
[target_account.id, list_id, 'list']
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,6 +32,8 @@ class List < ApplicationRecord
|
|||
|
||||
before_destroy :clean_feed_manager
|
||||
|
||||
scope :with_list_account, ->(account) { joins(:list_accounts).where(list_accounts: { account: }) }
|
||||
|
||||
private
|
||||
|
||||
def validate_account_lists_limit
|
||||
|
|
|
@ -82,7 +82,7 @@ class FollowService < BaseService
|
|||
|
||||
LocalNotificationWorker.perform_async(@target_account.id, follow.id, follow.class.name, 'follow')
|
||||
MergeWorker.perform_async(@target_account.id, @source_account.id, 'home')
|
||||
MergeWorker.push_bulk(List.where(account: @source_account).joins(:list_accounts).where(list_accounts: { account_id: @target_account.id }).pluck(:id)) do |list_id|
|
||||
MergeWorker.push_bulk(@source_account.owned_lists.with_list_account(@target_account).pluck(:id)) do |list_id|
|
||||
[@target_account.id, list_id, 'list']
|
||||
end
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class UnfollowService < BaseService
|
|||
|
||||
unless @options[:skip_unmerge]
|
||||
UnmergeWorker.perform_async(@target_account.id, @source_account.id, 'home')
|
||||
UnmergeWorker.push_bulk(List.where(account: @source_account).joins(:list_accounts).where(list_accounts: { account_id: @target_account.id }).pluck(:list_id)) do |list_id|
|
||||
UnmergeWorker.push_bulk(@source_account.owned_lists.with_list_account(@target_account).pluck(:list_id)) do |list_id|
|
||||
[@target_account.id, list_id, 'list']
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ class UnmuteService < BaseService
|
|||
if account.following?(target_account)
|
||||
MergeWorker.perform_async(target_account.id, account.id, 'home')
|
||||
|
||||
MergeWorker.push_bulk(List.where(account: account).joins(:list_accounts).where(list_accounts: { account_id: target_account.id }).pluck(:id)) do |list_id|
|
||||
MergeWorker.push_bulk(account.owned_lists.with_list_account(target_account).pluck(:id)) do |list_id|
|
||||
[target_account.id, list_id, 'list']
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,4 +28,26 @@ RSpec.describe List do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Scopes' do
|
||||
describe '.with_list_account' do
|
||||
let(:alice) { Fabricate :account }
|
||||
let(:bob) { Fabricate :account }
|
||||
let(:list) { Fabricate :list }
|
||||
let(:other_list) { Fabricate :list }
|
||||
|
||||
before do
|
||||
Fabricate :follow, account: list.account, target_account: alice
|
||||
Fabricate :follow, account: other_list.account, target_account: bob
|
||||
Fabricate :list_account, list: list, account: alice
|
||||
Fabricate :list_account, list: other_list, account: bob
|
||||
end
|
||||
|
||||
it 'returns lists connected to the account' do
|
||||
expect(described_class.with_list_account(alice))
|
||||
.to include(list)
|
||||
.and not_include(other_list)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user