The code powering m.abunchtell.com https://m.abunchtell.com
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 

67 рядки
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.reject_media?(account.domain)
  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.reject_media?(account.domain)
  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