Default follows for new users (#4871)
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)th-downstream
parent
63cb303a66
commit
6628ea4a82
@ -0,0 +1,34 @@
|
||||
# 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
|
@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class BootstrapTimelineWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
def perform(account_id)
|
||||
BootstrapTimelineService.new.call(Account.find(account_id))
|
||||
end
|
||||
end
|
@ -0,0 +1,37 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe BootstrapTimelineService do
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#call' do
|
||||
let(:source_account) { Fabricate(:account) }
|
||||
|
||||
context 'when setting is empty' do
|
||||
let!(:admin) { Fabricate(:user, admin: true) }
|
||||
|
||||
before do
|
||||
Setting.bootstrap_timeline_accounts = nil
|
||||
subject.call(source_account)
|
||||
end
|
||||
|
||||
it 'follows admin accounts from account' do
|
||||
expect(source_account.following?(admin.account)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when setting is set' do
|
||||
let!(:alice) { Fabricate(:account, username: 'alice') }
|
||||
let!(:bob) { Fabricate(:account, username: 'bob') }
|
||||
|
||||
before do
|
||||
Setting.bootstrap_timeline_accounts = 'alice, bob'
|
||||
subject.call(source_account)
|
||||
end
|
||||
|
||||
it 'follows found accounts from account' do
|
||||
expect(source_account.following?(alice)).to be true
|
||||
expect(source_account.following?(bob)).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in new issue