Fix quote is not set in noteserializer
This commit is contained in:
parent
77eb7c03d9
commit
818bcc0277
4 changed files with 33 additions and 3 deletions
|
@ -29,6 +29,7 @@ module ContextHelper
|
|||
limited_scope: { 'kmyblue' => 'http://kmy.blue/ns#', 'limitedScope' => { '@id' => 'kmyblue:limitedScope', '@type' => '@id' } },
|
||||
other_setting: { 'fedibird' => 'http://fedibird.com/ns#', 'otherSetting' => 'fedibird:otherSetting' },
|
||||
references: { 'fedibird' => 'http://fedibird.com/ns#', 'references' => { '@id' => 'fedibird:references', '@type' => '@id' } },
|
||||
quote_uri: { 'fedibird' => 'http://fedibird.com/ns#', 'quoteUri' => 'fedibird:quoteUri' },
|
||||
olm: {
|
||||
'toot' => 'http://joinmastodon.org/ns#', 'Device' => 'toot:Device', 'Ed25519Signature' => 'toot:Ed25519Signature', 'Ed25519Key' => 'toot:Ed25519Key', 'Curve25519Key' => 'toot:Curve25519Key', 'EncryptedMessage' => 'toot:EncryptedMessage', 'publicKeyBase64' => 'toot:publicKeyBase64', 'deviceId' => 'toot:deviceId',
|
||||
'claim' => { '@type' => '@id', '@id' => 'toot:claim' },
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
|
||||
module ActivityPub::CaseTransform
|
||||
class << self
|
||||
NO_CONVERT_VALUES = %w(
|
||||
_misskey_content
|
||||
_misskey_quote
|
||||
).freeze
|
||||
|
||||
def camel_lower_cache
|
||||
@camel_lower_cache ||= {}
|
||||
end
|
||||
|
@ -12,7 +17,9 @@ module ActivityPub::CaseTransform
|
|||
when Hash then value.deep_transform_keys! { |key| camel_lower(key) }
|
||||
when Symbol then camel_lower(value.to_s).to_sym
|
||||
when String
|
||||
camel_lower_cache[value] ||= if value.start_with?('_:')
|
||||
camel_lower_cache[value] ||= if NO_CONVERT_VALUES.include?(value)
|
||||
value
|
||||
elsif value.start_with?('_:')
|
||||
"_:#{value.delete_prefix('_:').underscore.camelize(:lower)}"
|
||||
else
|
||||
value.underscore.camelize(:lower)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
class ActivityPub::NoteSerializer < ActivityPub::Serializer
|
||||
include FormattingHelper
|
||||
|
||||
context_extensions :atom_uri, :conversation, :sensitive, :voters_count, :searchable_by, :references, :limited_scope
|
||||
context_extensions :atom_uri, :conversation, :sensitive, :voters_count, :searchable_by, :references, :limited_scope, :quote_uri
|
||||
|
||||
attributes :id, :type, :summary,
|
||||
:in_reply_to, :published, :url,
|
||||
|
@ -165,7 +165,7 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
|
|||
end
|
||||
|
||||
def quote?
|
||||
object.references.count == 1 && object.account.user&.single_ref_to_quote
|
||||
object.references.count == 1 && object.account.user&.settings&.[]('single_ref_to_quote')
|
||||
end
|
||||
|
||||
def quote_uri
|
||||
|
|
|
@ -13,8 +13,12 @@ describe ActivityPub::NoteSerializer do
|
|||
let!(:reply_by_other_first) { Fabricate(:status, account: other, thread: parent, visibility: :public) }
|
||||
let!(:reply_by_account_third) { Fabricate(:status, account: account, thread: parent, visibility: :public) }
|
||||
let!(:reply_by_account_visibility_direct) { Fabricate(:status, account: account, thread: parent, visibility: :direct) }
|
||||
let!(:referred) { nil }
|
||||
let(:convert_to_quote) { false }
|
||||
|
||||
before(:each) do
|
||||
parent.references << referred if referred.present?
|
||||
account.user&.settings&.[]=('single_ref_to_quote', true) if convert_to_quote
|
||||
@serialization = ActiveModelSerializers::SerializableResource.new(parent, serializer: described_class, adapter: ActivityPub::Adapter)
|
||||
end
|
||||
|
||||
|
@ -41,4 +45,22 @@ describe ActivityPub::NoteSerializer do
|
|||
it 'does not include replies with direct visibility in its replies collection' do
|
||||
expect(subject['replies']['first']['items']).to_not include(reply_by_account_visibility_direct.uri)
|
||||
end
|
||||
|
||||
context 'when has quote but no_convert setting' do
|
||||
let(:referred) { Fabricate(:status) }
|
||||
|
||||
it 'has as reference' do
|
||||
expect(subject['quoteUri']).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when has quote and convert setting' do
|
||||
let(:referred) { Fabricate(:status) }
|
||||
let(:convert_to_quote) { true }
|
||||
|
||||
it 'has as quote' do
|
||||
expect(subject['quoteUri']).to_not be_nil
|
||||
expect(subject['_misskey_quote'] == subject['quoteUri']).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue