update_account_service.rb 992 B

1234567891011121314151617181920212223242526272829303132333435
  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 => de
  13. account.errors.add(:avatar, de.message)
  14. false
  15. end
  16. private
  17. def authorize_all_follow_requests(account)
  18. AuthorizeFollowWorker.push_bulk(FollowRequest.where(target_account: account).select(:account_id, :target_account_id)) do |req|
  19. [req.account_id, req.target_account_id]
  20. end
  21. end
  22. def check_links(account)
  23. VerifyAccountLinksWorker.perform_async(account.id)
  24. end
  25. def process_hashtags(account)
  26. account.tags_as_strings = Extractor.extract_hashtags(account.note)
  27. end
  28. end