2017-08-26 12:40:03 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UpdateAccountService < BaseService
|
|
|
|
def call(account, params, raise_error: false)
|
2018-09-18 16:45:58 +02:00
|
|
|
was_locked = account.locked
|
2017-08-26 12:40:03 +02:00
|
|
|
update_method = raise_error ? :update! : :update
|
2018-09-18 16:45:58 +02:00
|
|
|
|
2017-08-26 12:40:03 +02:00
|
|
|
account.send(update_method, params).tap do |ret|
|
|
|
|
next unless ret
|
2018-09-18 16:45:58 +02:00
|
|
|
|
2017-08-26 12:40:03 +02:00
|
|
|
authorize_all_follow_requests(account) if was_locked && !account.locked
|
2018-09-18 16:45:58 +02:00
|
|
|
VerifyAccountLinksWorker.perform_async(@account.id) if account.fields_changed?
|
2017-08-26 12:40:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def authorize_all_follow_requests(account)
|
|
|
|
follow_requests = FollowRequest.where(target_account: account)
|
|
|
|
AuthorizeFollowWorker.push_bulk(follow_requests) do |req|
|
|
|
|
[req.account_id, req.target_account_id]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|