update_remote_profile_service.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. class UpdateRemoteProfileService < BaseService
  3. attr_reader :account, :remote_profile
  4. def call(body, account, resubscribe = false)
  5. @account = account
  6. @remote_profile = RemoteProfile.new(body)
  7. return if remote_profile.root.nil?
  8. update_account unless remote_profile.author.nil?
  9. old_hub_url = account.hub_url
  10. account.hub_url = remote_profile.hub_link if remote_profile.hub_link.present? && remote_profile.hub_link != old_hub_url
  11. account.save_with_optional_media!
  12. Pubsubhubbub::SubscribeWorker.perform_async(account.id) if resubscribe && account.hub_url != old_hub_url
  13. end
  14. private
  15. def update_account
  16. account.display_name = remote_profile.display_name || ''
  17. account.note = remote_profile.note || ''
  18. account.locked = remote_profile.locked?
  19. if !account.suspended? && !DomainBlock.find_by(domain: account.domain)&.reject_media?
  20. if remote_profile.avatar.present?
  21. account.avatar_remote_url = remote_profile.avatar
  22. else
  23. account.avatar_remote_url = ''
  24. account.avatar.destroy
  25. end
  26. if remote_profile.header.present?
  27. account.header_remote_url = remote_profile.header
  28. else
  29. account.header_remote_url = ''
  30. account.header.destroy
  31. end
  32. end
  33. end
  34. end