2017-08-26 04:40:03 -06:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UpdateAccountService < BaseService
|
|
|
|
def call(account, params, raise_error: false)
|
2018-09-18 08:45:58 -06:00
|
|
|
was_locked = account.locked
|
2017-08-26 04:40:03 -06:00
|
|
|
update_method = raise_error ? :update! : :update
|
2018-09-18 08:45:58 -06:00
|
|
|
|
2017-08-26 04:40:03 -06:00
|
|
|
account.send(update_method, params).tap do |ret|
|
|
|
|
next unless ret
|
2018-09-18 08:45:58 -06:00
|
|
|
|
2017-08-26 04:40:03 -06:00
|
|
|
authorize_all_follow_requests(account) if was_locked && !account.locked
|
2018-09-18 15:57:21 -06:00
|
|
|
check_links(account)
|
2018-12-06 09:36:11 -07:00
|
|
|
process_hashtags(account)
|
2017-08-26 04:40:03 -06:00
|
|
|
end
|
2020-08-31 19:04:00 -06:00
|
|
|
rescue Mastodon::DimensionsValidationError, Mastodon::StreamValidationError => e
|
|
|
|
account.errors.add(:avatar, e.message)
|
2018-12-13 21:07:21 -07:00
|
|
|
false
|
2017-08-26 04:40:03 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def authorize_all_follow_requests(account)
|
2019-09-27 13:13:51 -06:00
|
|
|
follow_requests = FollowRequest.where(target_account: account)
|
2023-12-15 08:52:00 -07:00
|
|
|
follow_requests = follow_requests.preload(:account).reject { |req| req.account.silenced? }
|
2023-03-14 20:45:15 -06:00
|
|
|
AuthorizeFollowWorker.push_bulk(follow_requests, limit: 1_000) do |req|
|
2017-08-26 04:40:03 -06:00
|
|
|
[req.account_id, req.target_account_id]
|
|
|
|
end
|
|
|
|
end
|
2018-09-18 15:57:21 -06:00
|
|
|
|
|
|
|
def check_links(account)
|
2023-10-11 07:14:18 -06:00
|
|
|
return unless account.fields.any?(&:requires_verification?)
|
|
|
|
|
2023-11-13 09:17:05 -07:00
|
|
|
VerifyAccountLinksWorker.perform_async(account.id)
|
2018-09-18 15:57:21 -06:00
|
|
|
end
|
2018-12-06 09:36:11 -07:00
|
|
|
|
|
|
|
def process_hashtags(account)
|
|
|
|
account.tags_as_strings = Extractor.extract_hashtags(account.note)
|
|
|
|
end
|
2017-08-26 04:40:03 -06:00
|
|
|
end
|