You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.4 KiB

  1. class RejectFollowingBlockedUsers < ActiveRecord::Migration[5.2]
  2. disable_ddl_transaction!
  3. def up
  4. blocked_follows = Follow.find_by_sql(<<-SQL)
  5. select f.* from follows f
  6. inner join blocks b on
  7. f.account_id = b.target_account_id and
  8. f.target_account_id = b.account_id
  9. SQL
  10. domain_blocked_follows = Follow.find_by_sql(<<-SQL)
  11. select f.* from follows f
  12. inner join accounts following on f.account_id = following.id
  13. inner join account_domain_blocks b on
  14. lower(b.domain) = lower(following.domain) and
  15. f.target_account_id = b.account_id
  16. SQL
  17. follows = (blocked_follows + domain_blocked_follows).uniq
  18. say "Destroying #{follows.size} blocked follow relationships..."
  19. follows.each do |follow|
  20. blocked_account = follow.account
  21. followed_acccount = follow.target_account
  22. next follow.destroy! if blocked_account.local?
  23. reject_follow_json = Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(follow, serializer: ActivityPub::RejectFollowSerializer, adapter: ActivityPub::Adapter).as_json).sign!(followed_acccount))
  24. ActivityPub::DeliveryWorker.perform_async(reject_follow_json, followed_acccount, blocked_account.inbox_url)
  25. follow.destroy!
  26. end
  27. end
  28. def down
  29. raise ActiveRecord::IrreversibleMigration
  30. end
  31. end