bootstrap_timeline_service.rb 1.0 KB

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