update_account_service.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # frozen_string_literal: true
  2. class UpdateAccountService < BaseService
  3. def call(account, params, raise_error: false)
  4. was_locked = account.locked
  5. update_method = raise_error ? :update! : :update
  6. account.send(update_method, params).tap do |ret|
  7. next unless ret
  8. authorize_all_follow_requests(account) if was_locked && !account.locked
  9. check_links(account)
  10. process_hashtags(account)
  11. end
  12. rescue Mastodon::DimensionsValidationError, Mastodon::StreamValidationError => e
  13. account.errors.add(:avatar, e.message)
  14. false
  15. end
  16. private
  17. def authorize_all_follow_requests(account)
  18. follow_requests = FollowRequest.where(target_account: account)
  19. follow_requests = follow_requests.preload(:account).select { |req| !req.account.silenced? }
  20. AuthorizeFollowWorker.push_bulk(follow_requests) do |req|
  21. [req.account_id, req.target_account_id]
  22. end
  23. end
  24. def check_links(account)
  25. VerifyAccountLinksWorker.perform_async(account.id)
  26. end
  27. def process_hashtags(account)
  28. account.tags_as_strings = Extractor.extract_hashtags(account.note)
  29. end
  30. end