about summary refs log tree commit diff
path: root/app/services/process_interaction_service.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-11-30 21:32:11 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-11-30 21:34:59 +0100
commit14bd46946d25186044485aa101dd2da976b61181 (patch)
tree94b59b79d06165469a103b9391ddfaee537e0cab /app/services/process_interaction_service.rb
parent1b447c190eb47117e99ff1e3c754f9cc461202f1 (diff)
Per-status control for unlisted mode, also federation for unlisted mode
Fix #233, fix #268
Diffstat (limited to 'app/services/process_interaction_service.rb')
-rw-r--r--app/services/process_interaction_service.rb19
1 files changed, 9 insertions, 10 deletions
diff --git a/app/services/process_interaction_service.rb b/app/services/process_interaction_service.rb
index 6b2f6e2d2..129b2a2be 100644
--- a/app/services/process_interaction_service.rb
+++ b/app/services/process_interaction_service.rb
@@ -1,8 +1,6 @@
 # frozen_string_literal: true
 
 class ProcessInteractionService < BaseService
-  ACTIVITY_NS = 'http://activitystrea.ms/spec/1.0/'
-
   # Record locally the remote interaction with our user
   # @param [String] envelope Salmon envelope
   # @param [Account] target_account Account the Salmon was addressed to
@@ -14,8 +12,8 @@ class ProcessInteractionService < BaseService
 
     return unless contains_author?(xml)
 
-    username = xml.at_xpath('/xmlns:entry/xmlns:author/xmlns:name').content
-    url      = xml.at_xpath('/xmlns:entry/xmlns:author/xmlns:uri').content
+    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).host
     account  = Account.find_by(username: username, domain: domain)
 
@@ -26,7 +24,7 @@ class ProcessInteractionService < BaseService
     end
 
     if salmon.verify(envelope, account.keypair)
-      update_remote_profile_service.call(xml.at_xpath('/xmlns:entry'), account, true)
+      update_remote_profile_service.call(xml.at_xpath('/xmlns:entry', xmlns: TagManager::XMLNS), account, true)
 
       case verb(xml)
       when :follow
@@ -50,16 +48,17 @@ class ProcessInteractionService < BaseService
   private
 
   def contains_author?(xml)
-    !(xml.at_xpath('/xmlns:entry/xmlns:author/xmlns:name').nil? || xml.at_xpath('/xmlns:entry/xmlns:author/xmlns:uri').nil?)
+    !(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"]').each { |mention_link| return true if mention_link.attribute('href').value == TagManager.instance.url_for(account) }
+    xml.xpath('/xmlns:entry/xmlns:link[@rel="mentioned"]', xmlns: TagManager::XMLNS).each { |mention_link| return true if mention_link.attribute('href').value == TagManager.instance.url_for(account) }
     false
   end
 
   def verb(xml)
-    xml.at_xpath('//activity:verb', activity: ACTIVITY_NS).content.gsub('http://activitystrea.ms/schema/1.0/', '').gsub('http://ostatus.org/schema/1.0/', '').to_sym
+    raw = xml.at_xpath('//activity:verb', activity: TagManager::AS_XMLNS).content
+    TagManager::VERBS.key(raw)
   rescue
     :post
   end
@@ -74,7 +73,7 @@ class ProcessInteractionService < BaseService
   end
 
   def delete_post!(xml, account)
-    status = Status.find(xml.at_xpath('//xmlns:id').content)
+    status = Status.find(xml.at_xpath('//xmlns:id', xmlns: TagManager::XMLNS).content)
 
     return if status.nil?
 
@@ -96,7 +95,7 @@ class ProcessInteractionService < BaseService
   end
 
   def activity_id(xml)
-    xml.at_xpath('//activity:object', activity: ACTIVITY_NS).at_xpath('./xmlns:id').content
+    xml.at_xpath('//activity:object', activity: TagManager::AS_XMLNS).at_xpath('./xmlns:id', xmlns: TagManager::XMLNS).content
   end
 
   def salmon