2018-06-09 18:38:17 -04:00
|
|
|
class RejectFollowingBlockedUsers < ActiveRecord::Migration[5.2]
|
|
|
|
disable_ddl_transaction!
|
|
|
|
|
|
|
|
def up
|
2023-04-30 00:43:50 -04:00
|
|
|
blocked_follows = Follow.find_by_sql(<<-SQL.squish)
|
2018-06-09 18:38:17 -04:00
|
|
|
select f.* from follows f
|
|
|
|
inner join blocks b on
|
|
|
|
f.account_id = b.target_account_id and
|
|
|
|
f.target_account_id = b.account_id
|
|
|
|
SQL
|
|
|
|
|
2023-04-30 00:43:50 -04:00
|
|
|
domain_blocked_follows = Follow.find_by_sql(<<-SQL.squish)
|
2018-06-09 18:38:17 -04:00
|
|
|
select f.* from follows f
|
|
|
|
inner join accounts following on f.account_id = following.id
|
|
|
|
inner join account_domain_blocks b on
|
|
|
|
lower(b.domain) = lower(following.domain) and
|
|
|
|
f.target_account_id = b.account_id
|
|
|
|
SQL
|
|
|
|
|
|
|
|
follows = (blocked_follows + domain_blocked_follows).uniq
|
|
|
|
say "Destroying #{follows.size} blocked follow relationships..."
|
|
|
|
|
|
|
|
follows.each do |follow|
|
|
|
|
blocked_account = follow.account
|
2022-03-06 16:51:40 -05:00
|
|
|
followed_account = follow.target_account
|
2018-06-09 18:38:17 -04:00
|
|
|
|
|
|
|
next follow.destroy! if blocked_account.local?
|
|
|
|
|
2022-03-06 16:51:40 -05:00
|
|
|
reject_follow_json = Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(follow, serializer: ActivityPub::RejectFollowSerializer, adapter: ActivityPub::Adapter).as_json).sign!(followed_account))
|
2018-06-09 18:38:17 -04:00
|
|
|
|
2022-03-06 16:51:40 -05:00
|
|
|
ActivityPub::DeliveryWorker.perform_async(reject_follow_json, followed_account, blocked_account.inbox_url)
|
2018-06-09 18:38:17 -04:00
|
|
|
|
|
|
|
follow.destroy!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
raise ActiveRecord::IrreversibleMigration
|
|
|
|
end
|
|
|
|
end
|