about summary refs log tree commit diff
path: root/app/services/activitypub
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/activitypub')
-rw-r--r--app/services/activitypub/fetch_remote_account_service.rb4
-rw-r--r--app/services/activitypub/fetch_remote_key_service.rb4
-rw-r--r--app/services/activitypub/process_account_service.rb28
3 files changed, 33 insertions, 3 deletions
diff --git a/app/services/activitypub/fetch_remote_account_service.rb b/app/services/activitypub/fetch_remote_account_service.rb
index d6ba625a9..5024853ca 100644
--- a/app/services/activitypub/fetch_remote_account_service.rb
+++ b/app/services/activitypub/fetch_remote_account_service.rb
@@ -3,6 +3,8 @@
 class ActivityPub::FetchRemoteAccountService < BaseService
   include JsonLdHelper
 
+  SUPPORTED_TYPES = %w(Application Group Organization Person Service).freeze
+
   # Should be called when uri has already been checked for locality
   # Does a WebFinger roundtrip on each call
   def call(uri, id: true, prefetched_body: nil)
@@ -54,6 +56,6 @@ class ActivityPub::FetchRemoteAccountService < BaseService
   end
 
   def expected_type?
-    @json['type'] == 'Person'
+    SUPPORTED_TYPES.include?(@json['type'])
   end
 end
diff --git a/app/services/activitypub/fetch_remote_key_service.rb b/app/services/activitypub/fetch_remote_key_service.rb
index ce1048fee..41837d462 100644
--- a/app/services/activitypub/fetch_remote_key_service.rb
+++ b/app/services/activitypub/fetch_remote_key_service.rb
@@ -43,7 +43,7 @@ class ActivityPub::FetchRemoteKeyService < BaseService
   end
 
   def person?
-    @json['type'] == 'Person'
+    ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES.include?(@json['type'])
   end
 
   def public_key?
@@ -55,6 +55,6 @@ class ActivityPub::FetchRemoteKeyService < BaseService
   end
 
   def confirmed_owner?
-    @owner['type'] == 'Person' && value_or_id(@owner['publicKey']) == @json['id']
+    ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES.include?(@owner['type']) && value_or_id(@owner['publicKey']) == @json['id']
   end
 end
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