The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

54 lines
1.6 KiB

  1. # frozen_string_literal: true
  2. class FollowService < BaseService
  3. # Follow a remote user, notify remote user about the follow
  4. # @param [Account] source_account From which to follow
  5. # @param [String] uri User URI to follow in the form of username@domain
  6. def call(source_account, uri)
  7. target_account = follow_remote_account_service.call(uri)
  8. raise ActiveRecord::RecordNotFound if target_account.nil? || target_account.id == source_account.id || target_account.suspended?
  9. raise Mastodon::NotPermitted if target_account.blocking?(source_account)
  10. if target_account.locked?
  11. request_follow(source_account, target_account)
  12. else
  13. direct_follow(source_account, target_account)
  14. end
  15. end
  16. private
  17. def request_follow(source_account, target_account)
  18. FollowRequest.create!(account: source_account, target_account: target_account)
  19. end
  20. def direct_follow(source_account, target_account)
  21. follow = source_account.follow!(target_account)
  22. if target_account.local?
  23. NotifyService.new.call(target_account, follow)
  24. else
  25. subscribe_service.call(target_account)
  26. NotificationWorker.perform_async(follow.stream_entry.id, target_account.id)
  27. end
  28. FeedManager.instance.merge_into_timeline(target_account, source_account)
  29. Pubsubhubbub::DistributionWorker.perform_async(follow.stream_entry.id)
  30. follow
  31. end
  32. def redis
  33. Redis.current
  34. end
  35. def follow_remote_account_service
  36. @follow_remote_account_service ||= FollowRemoteAccountService.new
  37. end
  38. def subscribe_service
  39. @subscribe_service ||= SubscribeService.new
  40. end
  41. end