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.8 KiB

  1. # frozen_string_literal: true
  2. class FollowMigrationService < FollowService
  3. # Follow an account with the same settings as another account, and unfollow the old account once the request is sent
  4. # @param [Account] source_account From which to follow
  5. # @param [Account] target_account Account to follow
  6. # @param [Account] old_target_account Account to unfollow once the follow request has been sent to the new one
  7. # @option [Boolean] bypass_locked Whether to immediately follow the new account even if it is locked
  8. def call(source_account, target_account, old_target_account, bypass_locked: false)
  9. @old_target_account = old_target_account
  10. follow = source_account.active_relationships.find_by(target_account: old_target_account)
  11. reblogs = follow&.show_reblogs?
  12. notify = follow&.notify?
  13. languages = follow&.languages
  14. super(source_account, target_account, reblogs: reblogs, notify: notify, languages: languages, bypass_locked: bypass_locked, bypass_limit: true)
  15. end
  16. private
  17. def request_follow!
  18. follow_request = @source_account.request_follow!(@target_account, **follow_options.merge(rate_limit: @options[:with_rate_limit], bypass_limit: @options[:bypass_limit]))
  19. if @target_account.local?
  20. LocalNotificationWorker.perform_async(@target_account.id, follow_request.id, follow_request.class.name, 'follow_request')
  21. UnfollowService.new.call(@source_account, @old_target_account, skip_unmerge: true)
  22. elsif @target_account.activitypub?
  23. ActivityPub::MigratedFollowDeliveryWorker.perform_async(build_json(follow_request), @source_account.id, @target_account.inbox_url, @old_target_account.id)
  24. end
  25. follow_request
  26. end
  27. def direct_follow!
  28. follow = super
  29. UnfollowService.new.call(@source_account, @old_target_account, skip_unmerge: true)
  30. follow
  31. end
  32. end