闭社主体 forked from https://github.com/tootsuite/mastodon
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.

46 lines
1.3 KiB

  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