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