about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authorDavid Yip <yipdw@member.fsf.org>2018-04-01 20:24:50 -0500
committerDavid Yip <yipdw@member.fsf.org>2018-04-01 20:24:50 -0500
commiteb39db7f93061c936fcb0bb24d5ba0c9a6186993 (patch)
treee12b5f5c9fec1d698024c88cd9f3ea9fe5b249cd /app/services
parentf0bb3ff53307aac7b9c64ec8a48d4ba1d2019513 (diff)
parentf890d2a766ae4c7fd8611dd4f3a15a13408f68c3 (diff)
Merge remote-tracking branch 'origin/master' into gs-master
  Conflicts:
 	app/javascript/mastodon/locales/en.json
 	app/javascript/mastodon/locales/ja.json
 	app/javascript/mastodon/locales/pl.json
 	app/views/accounts/_header.html.haml
Diffstat (limited to 'app/services')
-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
-rw-r--r--app/services/fetch_atom_service.rb2
-rw-r--r--app/services/resolve_account_service.rb2
-rw-r--r--app/services/resolve_url_service.rb2
-rw-r--r--app/services/update_remote_profile_service.rb21
7 files changed, 57 insertions, 6 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
diff --git a/app/services/fetch_atom_service.rb b/app/services/fetch_atom_service.rb
index 87076cc07..0444baf74 100644
--- a/app/services/fetch_atom_service.rb
+++ b/app/services/fetch_atom_service.rb
@@ -42,7 +42,7 @@ class FetchAtomService < BaseService
     elsif ['application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'].include?(response.mime_type)
       body = response.body_with_limit
       json = body_to_json(body)
-      if supported_context?(json) && json['type'] == 'Person' && json['inbox'].present?
+      if supported_context?(json) && ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES.include?(json['type']) && json['inbox'].present?
         [json['id'], { prefetched_body: body, id: true }, :activitypub]
       elsif supported_context?(json) && expected_type?(json)
         [json['id'], { prefetched_body: body, id: true }, :activitypub]
diff --git a/app/services/resolve_account_service.rb b/app/services/resolve_account_service.rb
index 744ea24f4..8cba88f01 100644
--- a/app/services/resolve_account_service.rb
+++ b/app/services/resolve_account_service.rb
@@ -189,7 +189,7 @@ class ResolveAccountService < BaseService
     return @actor_json if defined?(@actor_json)
 
     json        = fetch_resource(actor_url, false)
-    @actor_json = supported_context?(json) && json['type'] == 'Person' ? json : nil
+    @actor_json = supported_context?(json) && ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES.include?(json['type']) ? json : nil
   end
 
   def atom
diff --git a/app/services/resolve_url_service.rb b/app/services/resolve_url_service.rb
index 9499dc286..c19b568cb 100644
--- a/app/services/resolve_url_service.rb
+++ b/app/services/resolve_url_service.rb
@@ -17,7 +17,7 @@ class ResolveURLService < BaseService
 
   def process_url
     case type
-    when 'Person'
+    when 'Application', 'Group', 'Organization', 'Person', 'Service'
       FetchRemoteAccountService.new.call(atom_url, body, protocol)
     when 'Note', 'Article', 'Image', 'Video'
       FetchRemoteStatusService.new.call(atom_url, body, protocol)
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