summaryrefslogtreecommitdiffstats
path: root/app/services/process_interaction_service.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-05-03 17:02:18 +0200
committerGitHub <noreply@github.com>2017-05-03 17:02:18 +0200
commitbafd22ecf487774c252a271d668716b0e1c84c6c (patch)
treebda1f7d712b3d0094595b56261a36b38034d345b /app/services/process_interaction_service.rb
parentdd9d57300ba3b6df91ef6398d8c369437cc2a9c7 (diff)
Fix #2706 - Always respond with 200 to PuSH payloads (#2733)
Fix #2196 - Respond with 201 when Salmon accepted, 400 when unverified Fix #2629 - Correctly handle confirm_domain? for local accounts Unify rules for extracting author acct from XML, prefer <email>, fall back to <name> + <uri> (see also #2017, #2172)
Diffstat (limited to 'app/services/process_interaction_service.rb')
-rw-r--r--app/services/process_interaction_service.rb31
1 files changed, 4 insertions, 27 deletions
diff --git a/app/services/process_interaction_service.rb b/app/services/process_interaction_service.rb
index 410e805d345..1f15a265d57 100644
--- a/app/services/process_interaction_service.rb
+++ b/app/services/process_interaction_service.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
class ProcessInteractionService < BaseService
+ include AuthorExtractor
+
# Record locally the remote interaction with our user
# @param [String] envelope Salmon envelope
# @param [Account] target_account Account the Salmon was addressed to
@@ -10,18 +12,9 @@ class ProcessInteractionService < BaseService
xml = Nokogiri::XML(body)
xml.encoding = 'utf-8'
- return unless contains_author?(xml)
-
- username = xml.at_xpath('/xmlns:entry/xmlns:author/xmlns:name', xmlns: TagManager::XMLNS).content
- url = xml.at_xpath('/xmlns:entry/xmlns:author/xmlns:uri', xmlns: TagManager::XMLNS).content
- domain = Addressable::URI.parse(url).normalize.host
- account = Account.find_by(username: username, domain: domain)
-
- if account.nil?
- account = follow_remote_account_service.call("#{username}@#{domain}")
- end
+ account = author_from_xml(xml.at_xpath('/xmlns:entry', xmlns: TagManager::XMLNS))
- return if account.suspended?
+ return if account.nil? || account.suspended?
if salmon.verify(envelope, account.keypair)
RemoteProfileUpdateWorker.perform_async(account.id, body.force_encoding('UTF-8'), true)
@@ -59,10 +52,6 @@ class ProcessInteractionService < BaseService
private
- def contains_author?(xml)
- !(xml.at_xpath('/xmlns:entry/xmlns:author/xmlns:name', xmlns: TagManager::XMLNS).nil? || xml.at_xpath('/xmlns:entry/xmlns:author/xmlns:uri', xmlns: TagManager::XMLNS).nil?)
- end
-
def mentions_account?(xml, account)
xml.xpath('/xmlns:entry/xmlns:link[@rel="mentioned"]', xmlns: TagManager::XMLNS).each { |mention_link| return true if [TagManager.instance.uri_for(account), TagManager.instance.url_for(account)].include?(mention_link.attribute('href').value) }
false
@@ -144,16 +133,4 @@ class ProcessInteractionService < BaseService
def salmon
@salmon ||= OStatus2::Salmon.new
end
-
- def follow_remote_account_service
- @follow_remote_account_service ||= FollowRemoteAccountService.new
- end
-
- def process_feed_service
- @process_feed_service ||= ProcessFeedService.new
- end
-
- def remove_status_service
- @remove_status_service ||= RemoveStatusService.new
- end
end