move.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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
  6. return unless mark_as_processing!
  7. target_account = ActivityPub::FetchRemoteAccountService.new.call(target_uri)
  8. if target_account.nil? || target_account.suspended? || !target_account.also_known_as.include?(origin_account.uri)
  9. unmark_as_processing!
  10. return
  11. end
  12. # In case for some reason we didn't have a redirect for the profile already, set it
  13. origin_account.update(moved_to_account: target_account)
  14. # Initiate a re-follow for each follower
  15. MoveWorker.perform_async(origin_account.id, target_account.id)
  16. rescue
  17. unmark_as_processing!
  18. raise
  19. end
  20. private
  21. def origin_account
  22. @account
  23. end
  24. def target_uri
  25. value_or_id(@json['target'])
  26. end
  27. def mark_as_processing!
  28. redis.set("move_in_progress:#{@account.id}", true, nx: true, ex: PROCESSING_COOLDOWN)
  29. end
  30. def unmark_as_processing!
  31. redis.del("move_in_progress:#{@account.id}")
  32. end
  33. end