闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.9 KiB

  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. save_emojis if remote_profile.emojis.present?
  33. end
  34. end
  35. def save_emojis
  36. do_not_download = DomainBlock.find_by(domain: account.domain)&.reject_media?
  37. return if do_not_download
  38. remote_profile.emojis.each do |link|
  39. next unless link['href'] && link['name']
  40. shortcode = link['name'].delete(':')
  41. emoji = CustomEmoji.find_by(shortcode: shortcode, domain: account.domain)
  42. next unless emoji.nil?
  43. emoji = CustomEmoji.new(shortcode: shortcode, domain: account.domain)
  44. emoji.image_remote_url = link['href']
  45. emoji.save
  46. end
  47. end
  48. end