From 18fe946a602fc17f1787351c68538a5f864616b0 Mon Sep 17 00:00:00 2001 From: noellabo Date: Tue, 12 Nov 2019 20:20:08 +0900 Subject: [PATCH] Compatible with Misskey quote --- app/lib/activitypub/activity/create.rb | 12 ++++++++++-- app/lib/activitypub/case_transform.rb | 2 ++ app/serializers/activitypub/note_serializer.rb | 13 +++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index aefd02efe..e7b7e31a2 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -112,7 +112,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity conversation: conversation_from_uri(@object['conversation']), media_attachment_ids: process_attachments.take(4).map(&:id), poll: process_poll, - quote: quote_from_url(@object['quoteUrl']), + quote: quote, } end end @@ -383,7 +383,9 @@ class ActivityPub::Activity::Create < ActivityPub::Activity def text_from_content return Formatter.instance.linkify([[text_from_name, text_from_summary.presence].compact.join("\n\n"), object_url || object_uri].join(' ')) if converted_object_type? - if @object['content'].present? + if @object['quoteUrl'].blank? && @object['_misskey_quote'].present? + Formatter.instance.linkify(@object['_misskey_content']) + elsif @object['content'].present? @object['content'] elsif content_language_map? @object['contentMap'].values.first @@ -506,10 +508,16 @@ class ActivityPub::Activity::Create < ActivityPub::Activity retry end + def quote + @quote ||= quote_from_url(@object['quoteUrl'] || @object['_misskey_quote']) + end + def quote_from_url(url) return nil if url.nil? quote = ResolveURLService.new.call(url) status_from_uri(quote.uri) if quote + rescue + nil end end diff --git a/app/lib/activitypub/case_transform.rb b/app/lib/activitypub/case_transform.rb index 7f716f862..ef0c6e1f9 100644 --- a/app/lib/activitypub/case_transform.rb +++ b/app/lib/activitypub/case_transform.rb @@ -14,6 +14,8 @@ module ActivityPub::CaseTransform when String camel_lower_cache[value] ||= if value.start_with?('_:') '_:' + value.gsub(/\A_:/, '').underscore.camelize(:lower) + elsif value.start_with?('_') + value else value.underscore.camelize(:lower) end diff --git a/app/serializers/activitypub/note_serializer.rb b/app/serializers/activitypub/note_serializer.rb index c26d01caf..a9e15e6f8 100644 --- a/app/serializers/activitypub/note_serializer.rb +++ b/app/serializers/activitypub/note_serializer.rb @@ -7,8 +7,11 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer :in_reply_to, :published, :url, :attributed_to, :to, :cc, :sensitive, :atom_uri, :in_reply_to_atom_uri, - :conversation, :quote_url + :conversation + attribute :quote_url, if: -> { object.quote? } + attribute :misskey_quote, key: :_misskey_quote, if: -> { object.quote? } + attribute :misskey_content, key: :_misskey_content, if: -> { object.quote? } attribute :content attribute :content_map, if: :language? @@ -126,7 +129,13 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer end def quote_url - object.quote? ? ActivityPub::TagManager.instance.uri_for(object.quote) : nil + ActivityPub::TagManager.instance.uri_for(object.quote) if object.quote? + end + + alias misskey_quote quote_url + + def misskey_content + object.text if object.quote? end def local?