bootstrap_timeline_service.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # frozen_string_literal: true
  2. class BootstrapTimelineService < BaseService
  3. def call(source_account)
  4. @source_account = source_account
  5. autofollow_inviter!
  6. autofollow_bootstrap_timeline_accounts!
  7. end
  8. private
  9. def autofollow_inviter!
  10. return unless @source_account&.user&.invite&.autofollow?
  11. FollowService.new.call(@source_account, @source_account.user.invite.user.account)
  12. end
  13. def autofollow_bootstrap_timeline_accounts!
  14. bootstrap_timeline_accounts.each do |target_account|
  15. FollowService.new.call(@source_account, target_account)
  16. end
  17. end
  18. def bootstrap_timeline_accounts
  19. return @bootstrap_timeline_accounts if defined?(@bootstrap_timeline_accounts)
  20. @bootstrap_timeline_accounts = bootstrap_timeline_accounts_usernames.empty? ? admin_accounts : local_unlocked_accounts(bootstrap_timeline_accounts_usernames)
  21. end
  22. def bootstrap_timeline_accounts_usernames
  23. @bootstrap_timeline_accounts_usernames ||= (Setting.bootstrap_timeline_accounts || '').split(',').map { |str| str.strip.gsub(/\A@/, '') }.reject(&:blank?)
  24. end
  25. def admin_accounts
  26. User.admins
  27. .includes(:account)
  28. .where(accounts: { locked: false })
  29. .map(&:account)
  30. end
  31. def local_unlocked_accounts(usernames)
  32. Account.local
  33. .where(username: usernames)
  34. .where(locked: false)
  35. end
  36. end