summaryrefslogtreecommitdiffstats
path: root/app/services
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
parent1b447c190eb47117e99ff1e3c754f9cc461202f1 (diff)
Per-status control for unlisted mode, also federation for unlisted mode
Fix #233, fix #268
Diffstat (limited to 'app/services')
-rw-r--r--app/services/fan_out_on_write_service.rb2
-rw-r--r--app/services/post_status_service.rb2
-rw-r--r--app/services/process_feed_service.rb54
-rw-r--r--app/services/process_interaction_service.rb19
-rw-r--r--app/services/update_remote_profile_service.rb13
5 files changed, 46 insertions, 44 deletions
diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb
index 40d8a0feedf..ea9588becd7 100644
--- a/app/services/fan_out_on_write_service.rb
+++ b/app/services/fan_out_on_write_service.rb
@@ -8,7 +8,7 @@ class FanOutOnWriteService < BaseService
deliver_to_followers(status)
deliver_to_mentioned(status)
- return if status.account.silenced?
+ return if status.account.silenced? || !status.public_visibility?
deliver_to_hashtags(status)
deliver_to_public(status)
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb
index 979a157e96c..9e0ced129cb 100644
--- a/app/services/post_status_service.rb
+++ b/app/services/post_status_service.rb
@@ -10,7 +10,7 @@ class PostStatusService < BaseService
# @option [Enumerable] :media_ids Optional array of media IDs to attach
# @return [Status]
def call(account, text, in_reply_to = nil, options = {})
- status = account.statuses.create!(text: text, thread: in_reply_to, sensitive: options[:sensitive])
+ status = account.statuses.create!(text: text, thread: in_reply_to, sensitive: options[:sensitive], visibility: options[:unlisted] ? :unlisted : :public)
attach_media(status, options[:media_ids])
process_mentions_service.call(status)
process_hashtags_service.call(status)
diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb
index a7a4cb2b0b4..3aa0ceff8be 100644
--- a/app/services/process_feed_service.rb
+++ b/app/services/process_feed_service.rb
@@ -1,9 +1,6 @@
# frozen_string_literal: true
class ProcessFeedService < BaseService
- ACTIVITY_NS = 'http://activitystrea.ms/spec/1.0/'
- THREAD_NS = 'http://purl.org/syndication/thread/1.0'
-
def call(body, account)
xml = Nokogiri::XML(body)
xml.encoding = 'utf-8'
@@ -15,12 +12,12 @@ class ProcessFeedService < BaseService
private
def update_author(xml, account)
- return if xml.at_xpath('/xmlns:feed').nil?
- UpdateRemoteProfileService.new.call(xml.at_xpath('/xmlns:feed'), account, true)
+ return if xml.at_xpath('/xmlns:feed', xmlns: TagManager::XMLNS).nil?
+ UpdateRemoteProfileService.new.call(xml.at_xpath('/xmlns:feed', xmlns: TagManager::XMLNS), account, true)
end
def process_entries(xml, account)
- xml.xpath('//xmlns:entry').reverse_each.map { |entry| ProcessEntry.new.call(entry, account) }.compact
+ xml.xpath('//xmlns:entry', xmlns: TagManager::XMLNS).reverse_each.map { |entry| ProcessEntry.new.call(entry, account) }.compact
end
class ProcessEntry
@@ -48,7 +45,7 @@ class ProcessFeedService < BaseService
status = status_from_xml(@xml)
if verb == :share
- original_status = status_from_xml(@xml.at_xpath('.//activity:object', activity: ACTIVITY_NS))
+ original_status = status_from_xml(@xml.at_xpath('.//activity:object', activity: TagManager::AS_XMLNS))
status.reblog = original_status
if original_status.nil?
@@ -138,9 +135,15 @@ class ProcessFeedService < BaseService
def mentions_from_xml(parent, xml)
processed_account_ids = []
+ public_visibility = false
- xml.xpath('./xmlns:link[@rel="mentioned"]').each do |link|
- next if link['href'] == 'http://activityschema.org/collection/public'
+ xml.xpath('./xmlns:link[@rel="mentioned"]', xmlns: TagManager::XMLNS).each do |link|
+ if link['ostatus:object-type'] == TagManager::TYPES[:collection] && link['href'] == TagManager::COLLECTIONS[:public]
+ public_visibility = true
+ next
+ elsif link['ostatus:object-type'] == TagManager::TYPES[:group]
+ next
+ end
url = Addressable::URI.parse(link['href'])
@@ -160,15 +163,18 @@ class ProcessFeedService < BaseService
# So we can skip duplicate mentions
processed_account_ids << mentioned_account.id
end
+
+ parent.visibility = public_visibility ? :public : :unlisted
+ parent.save!
end
def hashtags_from_xml(parent, xml)
- tags = xml.xpath('./xmlns:category').map { |category| category['term'] }.select { |t| !t.blank? }
+ tags = xml.xpath('./xmlns:category', xmlns: TagManager::XMLNS).map { |category| category['term'] }.select { |t| !t.blank? }
ProcessHashtagsService.new.call(parent, tags)
end
def media_from_xml(parent, xml)
- xml.xpath('./xmlns:link[@rel="enclosure"]').each do |link|
+ xml.xpath('./xmlns:link[@rel="enclosure"]', xmlns: TagManager::XMLNS).each do |link|
next unless link['href']
media = MediaAttachment.where(status: parent, remote_url: link['href']).first_or_initialize(account: parent.account, status: parent, remote_url: link['href'])
@@ -183,52 +189,52 @@ class ProcessFeedService < BaseService
end
def id(xml = @xml)
- xml.at_xpath('./xmlns:id').content
+ xml.at_xpath('./xmlns:id', xmlns: TagManager::XMLNS).content
end
def verb(xml = @xml)
- raw = xml.at_xpath('./activity:verb', activity: ACTIVITY_NS).content
- raw.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
def type(xml = @xml)
- raw = xml.at_xpath('./activity:object-type', activity: ACTIVITY_NS).content
- raw.gsub('http://activitystrea.ms/schema/1.0/', '').gsub('http://ostatus.org/schema/1.0/', '').to_sym
+ raw = xml.at_xpath('./activity:object-type', activity: TagManager::AS_XMLNS).content
+ TagManager::TYPES.key(raw)
rescue
:activity
end
def url(xml = @xml)
- link = xml.at_xpath('./xmlns:link[@rel="alternate"]')
+ link = xml.at_xpath('./xmlns:link[@rel="alternate"]', xmlns: TagManager::XMLNS)
link.nil? ? nil : link['href']
end
def content(xml = @xml)
- xml.at_xpath('./xmlns:content').content
+ xml.at_xpath('./xmlns:content', xmlns: TagManager::XMLNS).content
end
def published(xml = @xml)
- xml.at_xpath('./xmlns:published').content
+ xml.at_xpath('./xmlns:published', xmlns: TagManager::XMLNS).content
end
def thread?(xml = @xml)
- !xml.at_xpath('./thr:in-reply-to', thr: THREAD_NS).nil?
+ !xml.at_xpath('./thr:in-reply-to', thr: TagManager::THR_XMLNS).nil?
end
def thread(xml = @xml)
- thr = xml.at_xpath('./thr:in-reply-to', thr: THREAD_NS)
+ thr = xml.at_xpath('./thr:in-reply-to', thr: TagManager::THR_XMLNS)
[thr['ref'], thr['href']]
end
def account?(xml = @xml)
- !xml.at_xpath('./xmlns:author').nil?
+ !xml.at_xpath('./xmlns:author', xmlns: TagManager::XMLNS).nil?
end
def acct(xml = @xml)
- username = xml.at_xpath('./xmlns:author/xmlns:name').content
- url = xml.at_xpath('./xmlns:author/xmlns:uri').content
+ username = xml.at_xpath('./xmlns:author/xmlns:name', xmlns: TagManager::XMLNS).content
+ url = xml.at_xpath('./xmlns:author/xmlns:uri', xmlns: TagManager::XMLNS).content
domain = Addressable::URI.parse(url).host
"#{username}@#{domain}"
diff --git a/app/services/process_interaction_service.rb b/app/services/process_interaction_service.rb
index 6b2f6e2d288..129b2a2bea4 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
diff --git a/app/services/update_remote_profile_service.rb b/app/services/update_remote_profile_service.rb
index 56b25816f2a..66d25dfeb36 100644
--- a/app/services/update_remote_profile_service.rb
+++ b/app/services/update_remote_profile_service.rb
@@ -1,19 +1,16 @@
# frozen_string_literal: true
class UpdateRemoteProfileService < BaseService
- POCO_NS = 'http://portablecontacts.net/spec/1.0'
- DFRN_NS = 'http://purl.org/macgirvin/dfrn/1.0'
-
def call(xml, account, resubscribe = false)
return if xml.nil?
- author_xml = xml.at_xpath('./xmlns:author') || xml.at_xpath('./dfrn:owner', dfrn: DFRN_NS)
- hub_link = xml.at_xpath('./xmlns:link[@rel="hub"]')
+ author_xml = xml.at_xpath('./xmlns:author', xmlns: TagManager::XMLNS) || xml.at_xpath('./dfrn:owner', dfrn: TagManager::DFRN_XMLNS)
+ hub_link = xml.at_xpath('./xmlns:link[@rel="hub"]', xmlns: TagManager::XMLNS)
unless author_xml.nil?
- account.display_name = author_xml.at_xpath('./poco:displayName', poco: POCO_NS).content unless author_xml.at_xpath('./poco:displayName', poco: POCO_NS).nil?
- account.note = author_xml.at_xpath('./poco:note', poco: POCO_NS).content unless author_xml.at_xpath('./poco:note').nil?
- account.avatar_remote_url = author_xml.at_xpath('./xmlns:link[@rel="avatar"]')['href'] unless author_xml.at_xpath('./xmlns:link[@rel="avatar"]').nil? || author_xml.at_xpath('./xmlns:link[@rel="avatar"]')['href'].blank?
+ account.display_name = author_xml.at_xpath('./poco:displayName', poco: TagManager::POCO_XMLNS).content unless author_xml.at_xpath('./poco:displayName', poco: TagManager::POCO_XMLNS).nil?
+ account.note = author_xml.at_xpath('./poco:note', poco: TagManager::POCO_XMLNS).content unless author_xml.at_xpath('./poco:note', poco: TagManager::POCO_XMLNS).nil?
+ account.avatar_remote_url = author_xml.at_xpath('./xmlns:link[@rel="avatar"]', xmlns: TagManager::XMLNS)['href'] unless author_xml.at_xpath('./xmlns:link[@rel="avatar"]', xmlns: TagManager::XMLNS).nil? || author_xml.at_xpath('./xmlns:link[@rel="avatar"]', xmlns: TagManager::XMLNS)['href'].blank?
end
old_hub_url = account.hub_url