about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authorReverite <github@reverite.sh>2019-03-30 23:42:55 -0700
committerReverite <github@reverite.sh>2019-03-30 23:42:55 -0700
commit4d77314005483e53e320a82c87805c6bcca1c463 (patch)
tree99f5b05bcbb1e8278517bf9a8f9ab114ab2dec45 /app/services
parente356a902d23a0ed87c62717085a37d34550c8464 (diff)
parent925830d11bb5c132e282f82bdb2ca893d87c9c24 (diff)
Merge branch 'glitch' into production
Diffstat (limited to 'app/services')
-rw-r--r--app/services/activitypub/fetch_remote_poll_service.rb1
-rw-r--r--app/services/activitypub/process_account_service.rb28
-rw-r--r--app/services/activitypub/process_poll_service.rb6
-rw-r--r--app/services/post_status_service.rb2
-rw-r--r--app/services/vote_service.rb4
5 files changed, 32 insertions, 9 deletions
diff --git a/app/services/activitypub/fetch_remote_poll_service.rb b/app/services/activitypub/fetch_remote_poll_service.rb
index 44a23712c..854a32d05 100644
--- a/app/services/activitypub/fetch_remote_poll_service.rb
+++ b/app/services/activitypub/fetch_remote_poll_service.rb
@@ -5,6 +5,7 @@ class ActivityPub::FetchRemotePollService < BaseService
 
   def call(poll, on_behalf_of = nil)
     json = fetch_resource(poll.status.uri, true, on_behalf_of)
+    return unless supported_context?(json)
     ActivityPub::ProcessPollService.new.call(poll, json)
   end
 end
diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb
index 5e3308428..6d0609ca0 100644
--- a/app/services/activitypub/process_account_service.rb
+++ b/app/services/activitypub/process_account_service.rb
@@ -24,6 +24,7 @@ class ActivityPub::ProcessAccountService < BaseService
         create_account if @account.nil?
         update_account
         process_tags
+        process_attachments
       else
         raise Mastodon::RaceConditionError
       end
@@ -151,7 +152,7 @@ class ActivityPub::ProcessAccountService < BaseService
 
   def property_values
     return unless @json['attachment'].is_a?(Array)
-    @json['attachment'].select { |attachment| attachment['type'] == 'PropertyValue' }.map { |attachment| attachment.slice('name', 'value') }
+    as_array(@json['attachment']).select { |attachment| attachment['type'] == 'PropertyValue' }.map { |attachment| attachment.slice('name', 'value') }
   end
 
   def mismatching_origin?(url)
@@ -231,6 +232,23 @@ class ActivityPub::ProcessAccountService < BaseService
     end
   end
 
+  def process_attachments
+    return if @json['attachment'].blank?
+
+    previous_proofs = @account.identity_proofs.to_a
+    current_proofs  = []
+
+    as_array(@json['attachment']).each do |attachment|
+      next unless equals_or_includes?(attachment['type'], 'IdentityProof')
+      current_proofs << process_identity_proof(attachment)
+    end
+
+    previous_proofs.each do |previous_proof|
+      next if current_proofs.any? { |current_proof| current_proof.id == previous_proof.id }
+      previous_proof.delete
+    end
+  end
+
   def process_emoji(tag)
     return if skip_download?
     return if tag['name'].blank? || tag['icon'].blank? || tag['icon']['url'].blank?
@@ -247,4 +265,12 @@ class ActivityPub::ProcessAccountService < BaseService
     emoji.image_remote_url = image_url
     emoji.save
   end
+
+  def process_identity_proof(attachment)
+    provider          = attachment['signatureAlgorithm']
+    provider_username = attachment['name']
+    token             = attachment['signatureValue']
+
+    @account.identity_proofs.where(provider: provider, provider_username: provider_username).find_or_create_by(provider: provider, provider_username: provider_username, token: token)
+  end
 end
diff --git a/app/services/activitypub/process_poll_service.rb b/app/services/activitypub/process_poll_service.rb
index ee248169d..61357abd3 100644
--- a/app/services/activitypub/process_poll_service.rb
+++ b/app/services/activitypub/process_poll_service.rb
@@ -5,7 +5,7 @@ class ActivityPub::ProcessPollService < BaseService
 
   def call(poll, json)
     @json = json
-    return unless supported_context? && expected_type?
+    return unless expected_type?
 
     previous_expires_at = poll.expires_at
 
@@ -54,10 +54,6 @@ class ActivityPub::ProcessPollService < BaseService
 
   private
 
-  def supported_context?
-    super(@json)
-  end
-
   def expected_type?
     equals_or_includes_any?(@json['type'], %w(Question))
   end
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb
index 820c553c9..333bf88d8 100644
--- a/app/services/post_status_service.rb
+++ b/app/services/post_status_service.rb
@@ -162,7 +162,7 @@ class PostStatusService < BaseService
       text: @text,
       media_attachments: @media || [],
       thread: @in_reply_to,
-      owned_poll_attributes: poll_attributes,
+      poll_attributes: poll_attributes,
       sensitive: (@options[:sensitive].nil? ? @account.user&.setting_default_sensitive : @options[:sensitive]) || @options[:spoiler_text].present?,
       spoiler_text: @options[:spoiler_text] || '',
       visibility: @visibility,
diff --git a/app/services/vote_service.rb b/app/services/vote_service.rb
index 0cace6c00..81af9ef3a 100644
--- a/app/services/vote_service.rb
+++ b/app/services/vote_service.rb
@@ -11,14 +11,14 @@ class VoteService < BaseService
     @choices = choices
     @votes   = []
 
-    return if @poll.expired?
-
     ApplicationRecord.transaction do
       @choices.each do |choice|
         @votes << @poll.votes.create!(account: @account, choice: choice)
       end
     end
 
+    ActivityTracker.increment('activity:interactions')
+
     if @poll.account.local?
       distribute_poll!
     else