Add QT attribute to send as quote

This commit is contained in:
KMY 2023-09-20 12:34:11 +09:00
parent d257157276
commit e16a885c81
3 changed files with 10 additions and 8 deletions

View file

@ -226,6 +226,10 @@ class Status < ApplicationRecord
!reblog_of_id.nil?
end
def quote
reference_objects.where(attribute_type: 'QT').first&.target_status
end
def within_realtime_window?
created_at >= REAL_TIME_WINDOW.ago
end

View file

@ -17,7 +17,6 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
attribute :quote_uri, if: :quote?
attribute :misskey_quote, key: :_misskey_quote, if: :quote?
attribute :misskey_content, key: :_misskey_content, if: :quote?
has_many :virtual_attachments, key: :attachment
has_many :virtual_tags, key: :tag
@ -172,21 +171,21 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
end
def quote?
object.references.count == 1 && object.account.user&.settings&.[]('single_ref_to_quote')
@quote ||= (object.reference_objects.count == 1 && object.account.user&.settings&.[]('single_ref_to_quote')) || object.reference_objects.where(attribute_type: 'QT').count == 1
end
def quote_post
@quote_post ||= object.quote || object.references.first
end
def quote_uri
ActivityPub::TagManager.instance.uri_for(object.references.first)
ActivityPub::TagManager.instance.uri_for(quote_post)
end
def misskey_quote
quote_uri
end
def misskey_content
object.text
end
def poll_options
object.preloadable_poll.loaded_options
end

View file

@ -73,7 +73,6 @@ describe ActivityPub::NoteSerializer do
expect(subject['quoteUri']).to_not be_nil
expect(subject['quoteUri']).to eq referred.uri
expect(subject['_misskey_quote']).to eq referred.uri
expect(subject['_misskey_content']).to eq referred.text
expect(subject['references']['first']['items']).to include referred.uri
end
end