The code powering m.abunchtell.com https://m.abunchtell.com
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

75 rader
1.7 KiB

  1. # frozen_string_literal: true
  2. class Form::AccountBatch
  3. include ActiveModel::Model
  4. include Authorization
  5. include Payloadable
  6. attr_accessor :account_ids, :action, :current_account
  7. def save
  8. case action
  9. when 'unfollow'
  10. unfollow!
  11. when 'remove_from_followers'
  12. remove_from_followers!
  13. when 'block_domains'
  14. block_domains!
  15. when 'approve'
  16. approve!
  17. when 'reject'
  18. reject!
  19. end
  20. end
  21. private
  22. def unfollow!
  23. accounts.find_each do |target_account|
  24. UnfollowService.new.call(current_account, target_account)
  25. end
  26. end
  27. def remove_from_followers!
  28. current_account.passive_relationships.where(account_id: account_ids).find_each do |follow|
  29. reject_follow!(follow)
  30. end
  31. end
  32. def block_domains!
  33. AfterAccountDomainBlockWorker.push_bulk(account_domains) do |domain|
  34. [current_account.id, domain]
  35. end
  36. end
  37. def account_domains
  38. accounts.pluck(Arel.sql('distinct domain')).compact
  39. end
  40. def accounts
  41. Account.where(id: account_ids)
  42. end
  43. def reject_follow!(follow)
  44. follow.destroy
  45. return unless follow.account.activitypub?
  46. ActivityPub::DeliveryWorker.perform_async(Oj.dump(serialize_payload(follow, ActivityPub::RejectFollowSerializer)), current_account.id, follow.account.inbox_url)
  47. end
  48. def approve!
  49. users = accounts.includes(:user).map(&:user)
  50. users.each { |user| authorize(user, :approve?) }
  51. .each(&:approve!)
  52. end
  53. def reject!
  54. records = accounts.includes(:user)
  55. records.each { |account| authorize(account.user, :reject?) }
  56. .each { |account| SuspendAccountService.new.call(account, reserve_email: false, reserve_username: false) }
  57. end
  58. end