闭社主体 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.

23 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. class UpdateRemoteProfileService < BaseService
  3. POCO_NS = 'http://portablecontacts.net/spec/1.0'
  4. DFRN_NS = 'http://purl.org/macgirvin/dfrn/1.0'
  5. def call(xml, account, resubscribe = false)
  6. author_xml = xml.at_xpath('./xmlns:author') || xml.at_xpath('./dfrn:owner', dfrn: DFRN_NS)
  7. hub_link = xml.at_xpath('./xmlns:link[@rel="hub"]')
  8. unless author_xml.nil?
  9. account.display_name = author_xml.at_xpath('./poco:displayName', poco: POCO_NS).content unless author_xml.at_xpath('./poco:displayName', poco: POCO_NS).nil?
  10. account.note = author_xml.at_xpath('./poco:note', poco: POCO_NS).content unless author_xml.at_xpath('./poco:note').nil?
  11. account.avatar_remote_url = author_xml.at_xpath('./xmlns:link[@rel="avatar"]')['href'] unless author_xml.at_xpath('./xmlns:link[@rel="avatar"]').nil? || author_xml.at_xpath('./xmlns:link[@rel="avatar"]')['href'].blank?
  12. end
  13. old_hub_url = account.hub_url
  14. account.hub_url = hub_link['href'] if !hub_link.nil? && !hub_link['href'].blank? && (hub_link['href'] != old_hub_url)
  15. account.save!
  16. SubscribeService.new.call(account) if resubscribe && (account.hub_url != old_hub_url)
  17. end
  18. end