summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>2017-09-20 01:08:08 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-09-19 18:08:08 +0200
commitbb4d005a8381091911697175416eb9c37379155e (patch)
treeddd7c17058fa7bf70dbc8ac8d5efa3ec64000680
parentdf1ce2350ccbedf145ad9a1b98582610cea80604 (diff)
Introduce OStatus::TagManager (#5008)
-rw-r--r--app/lib/activitypub/activity/create.rb2
-rw-r--r--app/lib/activitypub/tag_manager.rb4
-rw-r--r--app/lib/ostatus/activity/base.rb18
-rw-r--r--app/lib/ostatus/activity/creation.rb30
-rw-r--r--app/lib/ostatus/activity/share.rb2
-rw-r--r--app/lib/ostatus/atom_serializer.rb106
-rw-r--r--app/lib/ostatus/tag_manager.rb73
-rw-r--r--app/lib/tag_manager.rb67
-rw-r--r--app/models/remote_profile.rb12
-rw-r--r--app/serializers/activitypub/delete_serializer.rb2
-rw-r--r--app/serializers/activitypub/note_serializer.rb6
-rw-r--r--app/serializers/rest/status_serializer.rb2
-rw-r--r--app/services/concerns/author_extractor.rb6
-rw-r--r--app/services/fetch_remote_account_service.rb2
-rw-r--r--app/services/fetch_remote_status_service.rb2
-rw-r--r--app/services/process_feed_service.rb2
-rw-r--r--app/services/process_interaction_service.rb16
-rw-r--r--app/services/verify_salmon_service.rb2
-rw-r--r--spec/lib/activitypub/tag_manager_spec.rb2
-rw-r--r--spec/lib/ostatus/atom_serializer_spec.rb90
-rw-r--r--spec/lib/ostatus/tag_manager_spec.rb70
-rw-r--r--spec/lib/tag_manager_spec.rb65
-rw-r--r--spec/services/authorize_follow_service_spec.rb2
-rw-r--r--spec/services/batched_remove_status_service_spec.rb4
-rw-r--r--spec/services/block_service_spec.rb2
-rw-r--r--spec/services/favourite_service_spec.rb2
-rw-r--r--spec/services/follow_service_spec.rb4
-rw-r--r--spec/services/reject_follow_service_spec.rb2
-rw-r--r--spec/services/remove_status_service_spec.rb4
-rw-r--r--spec/services/unblock_service_spec.rb2
-rw-r--r--spec/services/unfollow_service_spec.rb2
31 files changed, 308 insertions, 297 deletions
diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb
index 41f2b0bad78..0964c9f536b 100644
--- a/app/lib/activitypub/activity/create.rb
+++ b/app/lib/activitypub/activity/create.rb
@@ -115,7 +115,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
def conversation_from_uri(uri)
return nil if uri.nil?
- return Conversation.find_by(id: TagManager.instance.unique_tag_to_local_id(uri, 'Conversation')) if TagManager.instance.local_id?(uri)
+ return Conversation.find_by(id: OStatus::TagManager.instance.unique_tag_to_local_id(uri, 'Conversation')) if OStatus::TagManager.instance.local_id?(uri)
Conversation.find_by(uri: uri) || Conversation.create!(uri: uri)
end
diff --git a/app/lib/activitypub/tag_manager.rb b/app/lib/activitypub/tag_manager.rb
index 1b4e271db56..4ec3b8c56ec 100644
--- a/app/lib/activitypub/tag_manager.rb
+++ b/app/lib/activitypub/tag_manager.rb
@@ -98,8 +98,8 @@ class ActivityPub::TagManager
else
StatusFinder.new(uri).status
end
- elsif ::TagManager.instance.local_id?(uri)
- klass.find_by(id: ::TagManager.instance.unique_tag_to_local_id(uri, klass.to_s))
+ elsif OStatus::TagManager.instance.local_id?(uri)
+ klass.find_by(id: OStatus::TagManager.instance.unique_tag_to_local_id(uri, klass.to_s))
else
klass.find_by(uri: uri.split('#').first)
end
diff --git a/app/lib/ostatus/activity/base.rb b/app/lib/ostatus/activity/base.rb
index 1dc7abee3f3..03938139797 100644
--- a/app/lib/ostatus/activity/base.rb
+++ b/app/lib/ostatus/activity/base.rb
@@ -11,30 +11,30 @@ class OStatus::Activity::Base
end
def verb
- raw = @xml.at_xpath('./activity:verb', activity: TagManager::AS_XMLNS).content
- TagManager::VERBS.key(raw)
+ raw = @xml.at_xpath('./activity:verb', activity: OStatus::TagManager::AS_XMLNS).content
+ OStatus::TagManager::VERBS.key(raw)
rescue
:post
end
def type
- raw = @xml.at_xpath('./activity:object-type', activity: TagManager::AS_XMLNS).content
- TagManager::TYPES.key(raw)
+ raw = @xml.at_xpath('./activity:object-type', activity: OStatus::TagManager::AS_XMLNS).content
+ OStatus::TagManager::TYPES.key(raw)
rescue
:activity
end
def id
- @xml.at_xpath('./xmlns:id', xmlns: TagManager::XMLNS).content
+ @xml.at_xpath('./xmlns:id', xmlns: OStatus::TagManager::XMLNS).content
end
def url
- link = @xml.xpath('./xmlns:link[@rel="alternate"]', xmlns: TagManager::XMLNS).find { |link_candidate| link_candidate['type'] == 'text/html' }
+ link = @xml.xpath('./xmlns:link[@rel="alternate"]', xmlns: OStatus::TagManager::XMLNS).find { |link_candidate| link_candidate['type'] == 'text/html' }
link.nil? ? nil : link['href']
end
def activitypub_uri
- link = @xml.xpath('./xmlns:link[@rel="alternate"]', xmlns: TagManager::XMLNS).find { |link_candidate| ['application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'].include?(link_candidate['type']) }
+ link = @xml.xpath('./xmlns:link[@rel="alternate"]', xmlns: OStatus::TagManager::XMLNS).find { |link_candidate| ['application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'].include?(link_candidate['type']) }
link.nil? ? nil : link['href']
end
@@ -45,8 +45,8 @@ class OStatus::Activity::Base
private
def find_status(uri)
- if TagManager.instance.local_id?(uri)
- local_id = TagManager.instance.unique_tag_to_local_id(uri, 'Status')
+ if OStatus::TagManager.instance.local_id?(uri)
+ local_id = OStatus::TagManager.instance.unique_tag_to_local_id(uri, 'Status')
return Status.find_by(id: local_id)
elsif ActivityPub::TagManager.instance.local_uri?(uri)
local_id = ActivityPub::TagManager.instance.uri_to_local_id(uri)
diff --git a/app/lib/ostatus/activity/creation.rb b/app/lib/ostatus/activity/creation.rb
index d3f1629c457..4f4ef2971ef 100644
--- a/app/lib/ostatus/activity/creation.rb
+++ b/app/lib/ostatus/activity/creation.rb
@@ -63,42 +63,42 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
end
def content
- @xml.at_xpath('./xmlns:content', xmlns: TagManager::XMLNS).content
+ @xml.at_xpath('./xmlns:content', xmlns: OStatus::TagManager::XMLNS).content
end
def content_language
- @xml.at_xpath('./xmlns:content', xmlns: TagManager::XMLNS)['xml:lang']&.presence || 'en'
+ @xml.at_xpath('./xmlns:content', xmlns: OStatus::TagManager::XMLNS)['xml:lang']&.presence || 'en'
end
def content_warning
- @xml.at_xpath('./xmlns:summary', xmlns: TagManager::XMLNS)&.content || ''
+ @xml.at_xpath('./xmlns:summary', xmlns: OStatus::TagManager::XMLNS)&.content || ''
end
def visibility_scope
- @xml.at_xpath('./mastodon:scope', mastodon: TagManager::MTDN_XMLNS)&.content&.to_sym || :public
+ @xml.at_xpath('./mastodon:scope', mastodon: OStatus::TagManager::MTDN_XMLNS)&.content&.to_sym || :public
end
def published
- @xml.at_xpath('./xmlns:published', xmlns: TagManager::XMLNS).content
+ @xml.at_xpath('./xmlns:published', xmlns: OStatus::TagManager::XMLNS).content
end
def thread?
- !@xml.at_xpath('./thr:in-reply-to', thr: TagManager::THR_XMLNS).nil?
+ !@xml.at_xpath('./thr:in-reply-to', thr: OStatus::TagManager::THR_XMLNS).nil?
end
def thread
- thr = @xml.at_xpath('./thr:in-reply-to', thr: TagManager::THR_XMLNS)
+ thr = @xml.at_xpath('./thr:in-reply-to', thr: OStatus::TagManager::THR_XMLNS)
[thr['ref'], thr['href']]
end
private
def find_or_create_conversation
- uri = @xml.at_xpath('./ostatus:conversation', ostatus: TagManager::OS_XMLNS)&.attribute('ref')&.content
+ uri = @xml.at_xpath('./ostatus:conversation', ostatus: OStatus::TagManager::OS_XMLNS)&.attribute('ref')&.content
return if uri.nil?
- if TagManager.instance.local_id?(uri)
- local_id = TagManager.instance.unique_tag_to_local_id(uri, 'Conversation')
+ if OStatus::TagManager.instance.local_id?(uri)
+ local_id = OStatus::TagManager.instance.unique_tag_to_local_id(uri, 'Conversation')
return Conversation.find_by(id: local_id)
end
@@ -108,8 +108,8 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
def save_mentions(parent)
processed_account_ids = []
- @xml.xpath('./xmlns:link[@rel="mentioned"]', xmlns: TagManager::XMLNS).each do |link|
- next if [TagManager::TYPES[:group], TagManager::TYPES[:collection]].include? link['ostatus:object-type']
+ @xml.xpath('./xmlns:link[@rel="mentioned"]', xmlns: OStatus::TagManager::XMLNS).each do |link|
+ next if [OStatus::TagManager::TYPES[:group], OStatus::TagManager::TYPES[:collection]].include? link['ostatus:object-type']
mentioned_account = account_from_href(link['href'])
@@ -123,14 +123,14 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
end
def save_hashtags(parent)
- tags = @xml.xpath('./xmlns:category', xmlns: TagManager::XMLNS).map { |category| category['term'] }.select(&:present?)
+ tags = @xml.xpath('./xmlns:category', xmlns: OStatus::TagManager::XMLNS).map { |category| category['term'] }.select(&:present?)
ProcessHashtagsService.new.call(parent, tags)
end
def save_media(parent)
do_not_download = DomainBlock.find_by(domain: parent.account.domain)&.reject_media?
- @xml.xpath('./xmlns:link[@rel="enclosure"]', xmlns: TagManager::XMLNS).each do |link|
+ @xml.xpath('./xmlns:link[@rel="enclosure"]', xmlns: OStatus::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'])
@@ -156,7 +156,7 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
return if do_not_download
- @xml.xpath('./xmlns:link[@rel="emoji"]', xmlns: TagManager::XMLNS).each do |link|
+ @xml.xpath('./xmlns:link[@rel="emoji"]', xmlns: OStatus::TagManager::XMLNS).each do |link|
next unless link['href'] && link['name']
shortcode = link['name'].delete(':')
diff --git a/app/lib/ostatus/activity/share.rb b/app/lib/ostatus/activity/share.rb
index 29000802165..5ca6014154b 100644
--- a/app/lib/ostatus/activity/share.rb
+++ b/app/lib/ostatus/activity/share.rb
@@ -10,7 +10,7 @@ class OStatus::Activity::Share < OStatus::Activity::Creation
end
def object
- @xml.at_xpath('.//activity:object', activity: TagManager::AS_XMLNS)
+ @xml.at_xpath('.//activity:object', activity: OStatus::TagManager::AS_XMLNS)
end
private
diff --git a/app/lib/ostatus/atom_serializer.rb b/app/lib/ostatus/atom_serializer.rb
index a6a5cb0c45f..a1ac11a5190 100644
--- a/app/lib/ostatus/atom_serializer.rb
+++ b/app/lib/ostatus/atom_serializer.rb
@@ -15,10 +15,10 @@ class OStatus::AtomSerializer
def author(account)
author = Ox::Element.new('author')
- uri = TagManager.instance.uri_for(account)
+ uri = OStatus::TagManager.instance.uri_for(account)
append_element(author, 'id', uri)
- append_element(author, 'activity:object-type', TagManager::TYPES[:person])
+ append_element(author, 'activity:object-type', OStatus::TagManager::TYPES[:person])
append_element(author, 'uri', uri)
append_element(author, 'name', account.username)
append_element(author, 'email', account.local? ? account.local_username_and_domain : account.acct)
@@ -65,15 +65,15 @@ class OStatus::AtomSerializer
add_namespaces(entry) if root
- append_element(entry, 'id', TagManager.instance.uri_for(stream_entry.status))
+ append_element(entry, 'id', OStatus::TagManager.instance.uri_for(stream_entry.status))
append_element(entry, 'published', stream_entry.created_at.iso8601)
append_element(entry, 'updated', stream_entry.updated_at.iso8601)
append_element(entry, 'title', stream_entry&.status&.title || "#{stream_entry.account.acct} deleted status")
entry << author(stream_entry.account) if root
- append_element(entry, 'activity:object-type', TagManager::TYPES[stream_entry.object_type])
- append_element(entry, 'activity:verb', TagManager::VERBS[stream_entry.verb])
+ append_element(entry, 'activity:object-type', OStatus::TagManager::TYPES[stream_entry.object_type])
+ append_element(entry, 'activity:verb', OStatus::TagManager::VERBS[stream_entry.verb])
entry << object(stream_entry.target) if stream_entry.targeted?
@@ -88,7 +88,7 @@ class OStatus::AtomSerializer
append_element(entry, 'link', nil, rel: :alternate, type: 'text/html', href: TagManager.instance.url_for(stream_entry.status))
append_element(entry, 'link', nil, rel: :self, type: 'application/atom+xml', href: account_stream_entry_url(stream_entry.account, stream_entry, format: 'atom'))
- append_element(entry, 'thr:in-reply-to', nil, ref: TagManager.instance.uri_for(stream_entry.thread), href: TagManager.instance.url_for(stream_entry.thread)) if stream_entry.threaded?
+ append_element(entry, 'thr:in-reply-to', nil, ref: OStatus::TagManager.instance.uri_for(stream_entry.thread), href: TagManager.instance.url_for(stream_entry.thread)) if stream_entry.threaded?
append_element(entry, 'ostatus:conversation', nil, ref: conversation_uri(stream_entry.status.conversation)) unless stream_entry&.status&.conversation_id.nil?
entry
@@ -97,20 +97,20 @@ class OStatus::AtomSerializer
def object(status)
object = Ox::Element.new('activity:object')
- append_element(object, 'id', TagManager.instance.uri_for(status))
+ append_element(object, 'id', OStatus::TagManager.instance.uri_for(status))
append_element(object, 'published', status.created_at.iso8601)
append_element(object, 'updated', status.updated_at.iso8601)
append_element(object, 'title', status.title)
object << author(status.account)
- append_element(object, 'activity:object-type', TagManager::TYPES[status.object_type])
- append_element(object, 'activity:verb', TagManager::VERBS[status.verb])
+ append_element(object, 'activity:object-type', OStatus::TagManager::TYPES[status.object_type])
+ append_element(object, 'activity:verb', OStatus::TagManager::VERBS[status.verb])
serialize_status_attributes(object, status)
append_element(object, 'link', nil, rel: :alternate, type: 'text/html', href: TagManager.instance.url_for(status))
- append_element(object, 'thr:in-reply-to', nil, ref: TagManager.instance.uri_for(status.thread), href: TagManager.instance.url_for(status.thread)) unless status.thread.nil?
+ append_element(object, 'thr:in-reply-to', nil, ref: OStatus::TagManager.instance.uri_for(status.thread), href: TagManager.instance.url_for(status.thread)) unless status.thread.nil?
append_element(object, 'ostatus:conversation', nil, ref: conversation_uri(status.conversation)) unless status.conversation_id.nil?
object
@@ -122,14 +122,14 @@ class OStatus::AtomSerializer
description = "#{follow.account.acct} started following #{follow.target_account.acct}"
- append_element(entry, 'id', TagManager.instance.unique_tag(follow.created_at, follow.id, 'Follow'))
+ append_element(entry, 'id', OStatus::TagManager.instance.unique_tag(follow.created_at, follow.id, 'Follow'))
append_element(entry, 'title', description)
append_element(entry, 'content', description, type: :html)
entry << author(follow.account)
- append_element(entry, 'activity:object-type', TagManager::TYPES[:activity])
- append_element(entry, 'activity:verb', TagManager::VERBS[:follow])
+ append_element(entry, 'activity:object-type', OStatus::TagManager::TYPES[:activity])
+ append_element(entry, 'activity:verb', OStatus::TagManager::VERBS[:follow])
object = author(follow.target_account)
object.value = 'activity:object'
@@ -142,13 +142,13 @@ class OStatus::AtomSerializer
entry = Ox::Element.new('entry')
add_namespaces(entry)
- append_element(entry, 'id', TagManager.instance.unique_tag(follow_request.created_at, follow_request.id, 'FollowRequest'))
+ append_element(entry, 'id', OStatus::TagManager.instance.unique_tag(follow_request.created_at, follow_request.id, 'FollowRequest'))
append_element(entry, 'title', "#{follow_request.account.acct} requested to follow #{follow_request.target_account.acct}")
entry << author(follow_request.account)
- append_element(entry, 'activity:object-type', TagManager::TYPES[:activity])
- append_element(entry, 'activity:verb', TagManager::VERBS[:request_friend])
+ append_element(entry, 'activity:object-type', OStatus::TagManager::TYPES[:activity])
+ append_element(entry, 'activity:verb', OStatus::TagManager::VERBS[:request_friend])
object = author(follow_request.target_account)
object.value = 'activity:object'
@@ -161,19 +161,19 @@ class OStatus::AtomSerializer
entry = Ox::Element.new('entry')
add_namespaces(entry)
- append_element(entry, 'id', TagManager.instance.unique_tag(Time.now.utc, follow_request.id, 'FollowRequest'))
+ append_element(entry, 'id', OStatus::TagManager.instance.unique_tag(Time.now.utc, follow_request.id, 'FollowRequest'))
append_element(entry, 'title', "#{follow_request.target_account.acct} authorizes follow request by #{follow_request.account.acct}")
entry << author(follow_request.target_account)
- append_element(entry, 'activity:object-type', TagManager::TYPES[:activity])
- append_element(entry, 'activity:verb', TagManager::VERBS[:authorize])
+ append_element(entry, 'activity:object-type', OStatus::TagManager::TYPES[:activity])
+ append_element(entry, 'activity:verb', OStatus::TagManager::VERBS[:authorize])
object = Ox::Element.new('activity:object')
object << author(follow_request.account)
- append_element(object, 'activity:object-type', TagManager::TYPES[:activity])
- append_element(object, 'activity:verb', TagManager::VERBS[:request_friend])
+ append_element(object, 'activity:object-type', OStatus::TagManager::TYPES[:activity])
+ append_element(object, 'activity:verb', OStatus::TagManager::VERBS[:request_friend])
inner_object = author(follow_request.target_account)
inner_object.value = 'activity:object'
@@ -187,19 +187,19 @@ class OStatus::AtomSerializer
entry = Ox::Element.new('entry')
add_namespaces(entry)
- append_element(entry, 'id', TagManager.instance.unique_tag(Time.now.utc, follow_request.id, 'FollowRequest'))
+ append_element(entry, 'id', OStatus::TagManager.instance.unique_tag(Time.now.utc, follow_request.id, 'FollowRequest'))
append_element(entry, 'title', "#{follow_request.target_account.acct} rejects follow request by #{follow_request.account.acct}")
entry << author(follow_request.target_account)
- append_element(entry, 'activity:object-type', TagManager::TYPES[:activity])
- append_element(entry, 'activity:verb', TagManager::VERBS[:reject])
+ append_element(entry, 'activity:object-type', OStatus::TagManager::TYPES[:activity])
+ append_element(entry, 'activity:verb', OStatus::TagManager::VERBS[:reject])
object = Ox::Element.new('activity:object')
object << author(follow_request.account)
- append_element(object, 'activity:object-type', TagManager::TYPES[:activity])
- append_element(object, 'activity:verb', TagManager::VERBS[:request_friend])
+ append_element(object, 'activity:object-type', OStatus::TagManager::TYPES[:activity])
+ append_element(object, 'activity:verb', OStatus::TagManager::VERBS[:request_friend])
inner_object = author(follow_request.target_account)
inner_object.value = 'activity:object'
@@ -215,14 +215,14 @@ class OStatus::AtomSerializer
description = "#{follow.account.acct} is no longer following #{follow.target_account.acct}"
- append_element(entry, 'id', TagManager.instance.unique_tag(Time.now.utc, follow.id, 'Follow'))
+ append_element(entry, 'id', OStatus::TagManager.instance.unique_tag(Time.now.utc, follow.id, 'Follow'))
append_element(entry, 'title', description)
append_element(entry, 'content', description, type: :html)
entry << author(follow.account)
- append_element(entry, 'activity:object-type', TagManager::TYPES[:activity])
- append_element(entry, 'activity:verb', TagManager::VERBS[:unfollow])
+ append_element(entry, 'activity:object-type', OStatus::TagManager::TYPES[:activity])
+ append_element(entry, 'activity:verb', OStatus::TagManager::VERBS[:unfollow])
object = author(follow.target_account)
object.value = 'activity:object'
@@ -237,13 +237,13 @@ class OStatus::AtomSerializer
description = "#{block.account.acct} no longer wishes to interact with #{block.target_account.acct}"
- append_element(entry, 'id', TagManager.instance.unique_tag(Time.now.utc, block.id,