Change lists to reflect added and removed users retroactively (#32930)
This commit is contained in:
parent
f2976ec9a4
commit
2b5faa2ba3
12 changed files with 157 additions and 25 deletions
33
app/services/add_accounts_to_list_service.rb
Normal file
33
app/services/add_accounts_to_list_service.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddAccountsToListService < BaseService
|
||||
def call(list, accounts)
|
||||
@list = list
|
||||
@accounts = accounts
|
||||
|
||||
return if @accounts.empty?
|
||||
|
||||
update_list!
|
||||
merge_into_list!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_list!
|
||||
ApplicationRecord.transaction do
|
||||
@accounts.each do |account|
|
||||
@list.accounts << account
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def merge_into_list!
|
||||
MergeWorker.push_bulk(merge_account_ids) do |account_id|
|
||||
[account_id, @list.id, 'list']
|
||||
end
|
||||
end
|
||||
|
||||
def merge_account_ids
|
||||
ListAccount.where(list: @list, account: @accounts).where.not(follow_id: nil).pluck(:account_id)
|
||||
end
|
||||
end
|
|
@ -81,7 +81,10 @@ class FollowService < BaseService
|
|||
follow = @source_account.follow!(@target_account, **follow_options.merge(rate_limit: @options[:with_rate_limit], bypass_limit: @options[:bypass_limit]))
|
||||
|
||||
LocalNotificationWorker.perform_async(@target_account.id, follow.id, follow.class.name, 'follow')
|
||||
MergeWorker.perform_async(@target_account.id, @source_account.id)
|
||||
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|
|
||||
[@target_account.id, list_id, 'list']
|
||||
end
|
||||
|
||||
follow
|
||||
end
|
||||
|
|
29
app/services/remove_accounts_from_list_service.rb
Normal file
29
app/services/remove_accounts_from_list_service.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RemoveAccountsFromListService < BaseService
|
||||
def call(list, accounts)
|
||||
@list = list
|
||||
@accounts = accounts
|
||||
|
||||
return if @accounts.empty?
|
||||
|
||||
unmerge_from_list!
|
||||
update_list!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_list!
|
||||
ListAccount.where(list: @list, account: @accounts).destroy_all
|
||||
end
|
||||
|
||||
def unmerge_from_list!
|
||||
UnmergeWorker.push_bulk(unmerge_account_ids) do |account_id|
|
||||
[account_id, @list.id, 'list']
|
||||
end
|
||||
end
|
||||
|
||||
def unmerge_account_ids
|
||||
ListAccount.where(list: @list, account: @accounts).where.not(follow_id: nil).pluck(:account_id)
|
||||
end
|
||||
end
|
|
@ -31,7 +31,13 @@ class UnfollowService < BaseService
|
|||
|
||||
create_notification(follow) if !@target_account.local? && @target_account.activitypub?
|
||||
create_reject_notification(follow) if @target_account.local? && !@source_account.local? && @source_account.activitypub?
|
||||
UnmergeWorker.perform_async(@target_account.id, @source_account.id) unless @options[:skip_unmerge]
|
||||
|
||||
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|
|
||||
[@target_account.id, list_id, 'list']
|
||||
end
|
||||
end
|
||||
|
||||
follow
|
||||
end
|
||||
|
|
|
@ -6,6 +6,12 @@ class UnmuteService < BaseService
|
|||
|
||||
account.unmute!(target_account)
|
||||
|
||||
MergeWorker.perform_async(target_account.id, account.id) if account.following?(target_account)
|
||||
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|
|
||||
[target_account.id, list_id, 'list']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue