remove_accounts_from_list_service.rb 612 B

1234567891011121314151617181920212223242526272829
  1. # frozen_string_literal: true
  2. class RemoveAccountsFromListService < BaseService
  3. def call(list, accounts)
  4. @list = list
  5. @accounts = accounts
  6. return if @accounts.empty?
  7. unmerge_from_list!
  8. update_list!
  9. end
  10. private
  11. def update_list!
  12. ListAccount.where(list: @list, account: @accounts).destroy_all
  13. end
  14. def unmerge_from_list!
  15. UnmergeWorker.push_bulk(unmerge_account_ids) do |account_id|
  16. [account_id, @list.id, 'list']
  17. end
  18. end
  19. def unmerge_account_ids
  20. ListAccount.where(list: @list, account: @accounts).where.not(follow_id: nil).pluck(:account_id)
  21. end
  22. end