mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-14 23:24:55 +01:00
7d7844a47f
When a new user confirms their e-mail, bootstrap their home timeline by automatically following a set of accounts. By default, all local admin accounts (that are unlocked). Can be customized by new admin setting (comma-separated usernames, local and unlocked only)
35 lines
1.0 KiB
Ruby
35 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class BootstrapTimelineService < BaseService
|
|
def call(source_account)
|
|
bootstrap_timeline_accounts.each do |target_account|
|
|
FollowService.new.call(source_account, target_account)
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def bootstrap_timeline_accounts
|
|
return @bootstrap_timeline_accounts if defined?(@bootstrap_timeline_accounts)
|
|
|
|
@bootstrap_timeline_accounts = bootstrap_timeline_accounts_usernames.empty? ? admin_accounts : local_unlocked_accounts(bootstrap_timeline_accounts_usernames)
|
|
end
|
|
|
|
def bootstrap_timeline_accounts_usernames
|
|
@bootstrap_timeline_accounts_usernames ||= (Setting.bootstrap_timeline_accounts || '').split(',').map { |str| str.strip.gsub(/\A@/, '') }.reject(&:blank?)
|
|
end
|
|
|
|
def admin_accounts
|
|
User.admins
|
|
.includes(:account)
|
|
.where(accounts: { locked: false })
|
|
.map(&:account)
|
|
end
|
|
|
|
def local_unlocked_accounts(usernames)
|
|
Account.local
|
|
.where(username: usernames)
|
|
.where(locked: false)
|
|
end
|
|
end
|