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.

43 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::Activity::Move < ActivityPub::Activity
  3. PROCESSING_COOLDOWN = 7.days.seconds
  4. def perform
  5. return if origin_account.uri != object_uri || processed?
  6. mark_as_processing!
  7. target_account = ActivityPub::FetchRemoteAccountService.new.call(target_uri)
  8. return if target_account.nil? || !target_account.also_known_as.include?(origin_account.uri)
  9. # In case for some reason we didn't have a redirect for the profile already, set it
  10. origin_account.update(moved_to_account: target_account) if origin_account.moved_to_account_id.nil?
  11. # Initiate a re-follow for each follower
  12. origin_account.followers.local.select(:id).find_in_batches do |follower_accounts|
  13. UnfollowFollowWorker.push_bulk(follower_accounts.map(&:id)) do |follower_account_id|
  14. [follower_account_id, origin_account.id, target_account.id]
  15. end
  16. end
  17. end
  18. private
  19. def origin_account
  20. @account
  21. end
  22. def target_uri
  23. value_or_id(@json['target'])
  24. end
  25. def processed?
  26. redis.exists("move_in_progress:#{@account.id}")
  27. end
  28. def mark_as_processing!
  29. redis.setex("move_in_progress:#{@account.id}", PROCESSING_COOLDOWN, true)
  30. end
  31. end