2016-11-15 16:56:29 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-28 14:26:26 +01:00
|
|
|
class UpdateRemoteProfileService < BaseService
|
2017-06-11 10:41:59 +02:00
|
|
|
attr_reader :account, :remote_profile
|
2017-04-08 13:26:03 +02:00
|
|
|
|
2017-06-11 10:41:59 +02:00
|
|
|
def call(body, account, resubscribe = false)
|
|
|
|
@account = account
|
|
|
|
@remote_profile = RemoteProfile.new(body)
|
2016-11-28 19:11:36 +01:00
|
|
|
|
2017-06-11 10:41:59 +02:00
|
|
|
return if remote_profile.root.nil?
|
2016-10-06 14:39:34 +02:00
|
|
|
|
2017-06-11 10:41:59 +02:00
|
|
|
update_account unless remote_profile.author.nil?
|
2016-02-28 14:26:26 +01:00
|
|
|
|
2016-11-26 15:12:57 +01:00
|
|
|
old_hub_url = account.hub_url
|
2017-06-11 10:41:59 +02:00
|
|
|
account.hub_url = remote_profile.hub_link if remote_profile.hub_link.present? && remote_profile.hub_link != old_hub_url
|
2016-12-02 14:14:49 +01:00
|
|
|
|
2017-05-05 21:37:02 +02:00
|
|
|
account.save_with_optional_media!
|
2016-11-26 15:12:57 +01:00
|
|
|
|
2017-06-11 10:41:59 +02:00
|
|
|
Pubsubhubbub::SubscribeWorker.perform_async(account.id) if resubscribe && account.hub_url != old_hub_url
|
2016-02-28 14:26:26 +01:00
|
|
|
end
|
2017-04-08 13:26:03 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-06-11 10:41:59 +02:00
|
|
|
def update_account
|
|
|
|
account.display_name = remote_profile.display_name || ''
|
|
|
|
account.note = remote_profile.note || ''
|
|
|
|
account.locked = remote_profile.locked?
|
2017-04-08 13:26:03 +02:00
|
|
|
|
2017-06-11 10:41:59 +02:00
|
|
|
if !account.suspended? && !DomainBlock.find_by(domain: account.domain)&.reject_media?
|
2017-06-14 18:01:27 +02:00
|
|
|
if remote_profile.avatar.present?
|
|
|
|
account.avatar_remote_url = remote_profile.avatar
|
|
|
|
else
|
|
|
|
account.avatar_remote_url = ''
|
|
|
|
account.avatar.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
if remote_profile.header.present?
|
|
|
|
account.header_remote_url = remote_profile.header
|
|
|
|
else
|
|
|
|
account.header_remote_url = ''
|
|
|
|
account.header.destroy
|
|
|
|
end
|
2018-04-01 23:55:42 +02:00
|
|
|
|
|
|
|
save_emojis(account) if remote_profile.emojis.present?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def save_emojis(parent)
|
|
|
|
do_not_download = DomainBlock.find_by(domain: parent.account.domain)&.reject_media?
|
|
|
|
|
|
|
|
return if do_not_download
|
|
|
|
|
|
|
|
remote_account.emojis.each do |link|
|
|
|
|
next unless link['href'] && link['name']
|
|
|
|
|
|
|
|
shortcode = link['name'].delete(':')
|
|
|
|
emoji = CustomEmoji.find_by(shortcode: shortcode, domain: parent.account.domain)
|
|
|
|
|
|
|
|
next unless emoji.nil?
|
|
|
|
|
|
|
|
emoji = CustomEmoji.new(shortcode: shortcode, domain: parent.account.domain)
|
|
|
|
emoji.image_remote_url = link['href']
|
|
|
|
emoji.save
|
2017-06-11 10:41:59 +02:00
|
|
|
end
|
2017-04-08 13:26:03 +02:00
|
|
|
end
|
2016-02-28 14:26:26 +01:00
|
|
|
end
|