diff options
author | David Underwood <davefp@gmail.com> | 2018-04-01 17:55:42 -0400 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2018-04-01 23:55:42 +0200 |
commit | 123a343d116d3e83cbd04460cc7bd0b6f3d208c4 (patch) | |
tree | 7d834be5438d835fe90744e0ba011f585cf252b1 /app/services | |
parent | f464f98fd3b8ef33b3afa5acf09e829c046134de (diff) |
[WIP] Enable custom emoji on account pages and in the sidebar (#6124)
Federate custom emojis with accounts
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/activitypub/process_account_service.rb | 28 | ||||
-rw-r--r-- | app/services/update_remote_profile_service.rb | 21 |
2 files changed, 49 insertions, 0 deletions
diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index 7d8dc1369..cf8462821 100644 --- a/app/services/activitypub/process_account_service.rb +++ b/app/services/activitypub/process_account_service.rb @@ -22,6 +22,7 @@ class ActivityPub::ProcessAccountService < BaseService create_account if @account.nil? update_account + process_tags(@account) end end @@ -187,4 +188,31 @@ class ActivityPub::ProcessAccountService < BaseService def lock_options { redis: Redis.current, key: "process_account:#{@uri}" } end + + def process_tags(account) + return if @json['tag'].blank? + as_array(@json['tag']).each do |tag| + case tag['type'] + when 'Emoji' + process_emoji tag, account + end + end + end + + def process_emoji(tag, _account) + return if skip_download? + return if tag['name'].blank? || tag['icon'].blank? || tag['icon']['url'].blank? + + shortcode = tag['name'].delete(':') + image_url = tag['icon']['url'] + uri = tag['id'] + updated = tag['updated'] + emoji = CustomEmoji.find_by(shortcode: shortcode, domain: @account.domain) + + return unless emoji.nil? || emoji.updated_at >= updated + + emoji ||= CustomEmoji.new(domain: @account.domain, shortcode: shortcode, uri: uri) + emoji.image_remote_url = image_url + emoji.save + end end diff --git a/app/services/update_remote_profile_service.rb b/app/services/update_remote_profile_service.rb index 49a907682..aca1185de 100644 --- a/app/services/update_remote_profile_service.rb +++ b/app/services/update_remote_profile_service.rb @@ -40,6 +40,27 @@ class UpdateRemoteProfileService < BaseService account.header_remote_url = '' account.header.destroy end + + 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 end end end |