Fix quote is not set in noteserializer

This commit is contained in:
KMY 2023-09-19 18:22:18 +09:00
parent 77eb7c03d9
commit 818bcc0277
4 changed files with 33 additions and 3 deletions

View file

@ -29,6 +29,7 @@ module ContextHelper
limited_scope: { 'kmyblue' => 'http://kmy.blue/ns#', 'limitedScope' => { '@id' => 'kmyblue:limitedScope', '@type' => '@id' } }, limited_scope: { 'kmyblue' => 'http://kmy.blue/ns#', 'limitedScope' => { '@id' => 'kmyblue:limitedScope', '@type' => '@id' } },
other_setting: { 'fedibird' => 'http://fedibird.com/ns#', 'otherSetting' => 'fedibird:otherSetting' }, other_setting: { 'fedibird' => 'http://fedibird.com/ns#', 'otherSetting' => 'fedibird:otherSetting' },
references: { 'fedibird' => 'http://fedibird.com/ns#', 'references' => { '@id' => 'fedibird:references', '@type' => '@id' } }, references: { 'fedibird' => 'http://fedibird.com/ns#', 'references' => { '@id' => 'fedibird:references', '@type' => '@id' } },
quote_uri: { 'fedibird' => 'http://fedibird.com/ns#', 'quoteUri' => 'fedibird:quoteUri' },
olm: { 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', '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' }, 'claim' => { '@type' => '@id', '@id' => 'toot:claim' },

View file

@ -2,6 +2,11 @@
module ActivityPub::CaseTransform module ActivityPub::CaseTransform
class << self class << self
NO_CONVERT_VALUES = %w(
_misskey_content
_misskey_quote
).freeze
def camel_lower_cache def camel_lower_cache
@camel_lower_cache ||= {} @camel_lower_cache ||= {}
end end
@ -12,7 +17,9 @@ module ActivityPub::CaseTransform
when Hash then value.deep_transform_keys! { |key| camel_lower(key) } when Hash then value.deep_transform_keys! { |key| camel_lower(key) }
when Symbol then camel_lower(value.to_s).to_sym when Symbol then camel_lower(value.to_s).to_sym
when String 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)}" "_:#{value.delete_prefix('_:').underscore.camelize(:lower)}"
else else
value.underscore.camelize(:lower) value.underscore.camelize(:lower)

View file

@ -3,7 +3,7 @@
class ActivityPub::NoteSerializer < ActivityPub::Serializer class ActivityPub::NoteSerializer < ActivityPub::Serializer
include FormattingHelper 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, attributes :id, :type, :summary,
:in_reply_to, :published, :url, :in_reply_to, :published, :url,
@ -165,7 +165,7 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
end end
def quote? 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 end
def quote_uri def quote_uri

View file

@ -13,8 +13,12 @@ describe ActivityPub::NoteSerializer do
let!(:reply_by_other_first) { Fabricate(:status, account: other, thread: parent, visibility: :public) } 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_third) { Fabricate(:status, account: account, thread: parent, visibility: :public) }
let!(:reply_by_account_visibility_direct) { Fabricate(:status, account: account, thread: parent, visibility: :direct) } 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 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) @serialization = ActiveModelSerializers::SerializableResource.new(parent, serializer: described_class, adapter: ActivityPub::Adapter)
end end
@ -41,4 +45,22 @@ describe ActivityPub::NoteSerializer do
it 'does not include replies with direct visibility in its replies collection' 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) expect(subject['replies']['first']['items']).to_not include(reply_by_account_visibility_direct.uri)
end 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 end