Compatible with Misskey quote

This commit is contained in:
noellabo 2019-11-12 20:20:08 +09:00
parent 9faf45d0fd
commit 18fe946a60
3 changed files with 23 additions and 4 deletions

View file

@ -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

View file

@ -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

View file

@ -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?