diff options
author | Surinna Curtis <ekiru.0@gmail.com> | 2017-09-10 14:10:30 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-10 14:10:30 -0500 |
commit | 7a9c7d4e0b694e716cb018e3057792b4d86026fa (patch) | |
tree | 973b16e23a7cbeaf5a43550444e54aa1ace50a46 /app/services | |
parent | c9df53044a333276853f7dc7ef2aed6d48df087f (diff) | |
parent | 932571fa22273e6ff5c229147668c426b4d65326 (diff) |
Merge pull request #143 from yipdw/sync/upstream
Merge with upstream's 1.6.0
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/bootstrap_timeline_service.rb | 34 | ||||
-rw-r--r-- | app/services/follow_service.rb | 4 |
2 files changed, 36 insertions, 2 deletions
diff --git a/app/services/bootstrap_timeline_service.rb b/app/services/bootstrap_timeline_service.rb new file mode 100644 index 000000000..c01e25824 --- /dev/null +++ b/app/services/bootstrap_timeline_service.rb @@ -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 diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb index 941556b60..791773f25 100644 --- a/app/services/follow_service.rb +++ b/app/services/follow_service.rb @@ -5,9 +5,9 @@ class FollowService < BaseService # Follow a remote user, notify remote user about the follow # @param [Account] source_account From which to follow - # @param [String] uri User URI to follow in the form of username@domain + # @param [String, Account] uri User URI to follow in the form of username@domain (or account record) def call(source_account, uri) - target_account = ResolveRemoteAccountService.new.call(uri) + target_account = uri.is_a?(Account) ? uri : ResolveRemoteAccountService.new.call(uri) raise ActiveRecord::RecordNotFound if target_account.nil? || target_account.id == source_account.id || target_account.suspended? raise Mastodon::NotPermittedError if target_account.blocking?(source_account) || source_account.blocking?(target_account) |