Add: _misskey_license
の送受信 (#968)
This commit is contained in:
parent
9c14810881
commit
c139f8947e
8 changed files with 110 additions and 3 deletions
|
@ -34,6 +34,7 @@ module ContextHelper
|
|||
license: { 'schema' => 'http://schema.org#', 'license' => 'schema:license' },
|
||||
suspended: { 'toot' => 'http://joinmastodon.org/ns#', 'suspended' => 'toot:suspended' },
|
||||
attribution_domains: { 'toot' => 'http://joinmastodon.org/ns#', 'attributionDomains' => { '@id' => 'toot:attributionDomains', '@type' => '@id' } },
|
||||
misskey_license: { 'misskey' => 'https://misskey-hub.net/ns#', '_misskey_license' => 'misskey:_misskey_license' },
|
||||
}.freeze
|
||||
|
||||
def full_context
|
||||
|
|
|
@ -4,6 +4,7 @@ module ActivityPub::CaseTransform
|
|||
class << self
|
||||
NO_CONVERT_VALUES = %w(
|
||||
_misskey_content
|
||||
_misskey_license
|
||||
_misskey_quote
|
||||
).freeze
|
||||
|
||||
|
|
|
@ -34,6 +34,6 @@ class ActivityPub::Parser::CustomEmojiParser
|
|||
end
|
||||
|
||||
def license
|
||||
@json['license'] || @json['licence']
|
||||
@json.dig('_misskey_license', 'freeText') || @json['license'] || @json['licence']
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::MisskeyEmojiLicensePresenter < ActiveModelSerializers::Model
|
||||
attributes :free_text
|
||||
end
|
|
@ -3,11 +3,12 @@
|
|||
class ActivityPub::EmojiSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
context_extensions :emoji, :license, :keywords
|
||||
context_extensions :emoji, :license, :keywords, :misskey_license
|
||||
|
||||
attributes :id, :type, :name, :keywords, :is_sensitive, :updated
|
||||
|
||||
attribute :license, if: -> { object.license.present? }
|
||||
attribute :license, if: :license?
|
||||
has_one :misskey_license, key: :_misskey_license, if: :license?, serializer: ActivityPub::MisskeyEmojiLicenseSerializer
|
||||
|
||||
has_one :icon, serializer: ActivityPub::ImageSerializer
|
||||
|
||||
|
@ -34,4 +35,12 @@ class ActivityPub::EmojiSerializer < ActivityPub::Serializer
|
|||
def name
|
||||
":#{object.shortcode}:"
|
||||
end
|
||||
|
||||
def misskey_license
|
||||
ActivityPub::MisskeyEmojiLicensePresenter.new(free_text: object.license)
|
||||
end
|
||||
|
||||
def license?
|
||||
object.license.present?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::MisskeyEmojiLicenseSerializer < ActivityPub::Serializer
|
||||
attribute :free_text, key: :freeText
|
||||
end
|
53
spec/lib/activitypub/parser/custom_emoji_parser_spec.rb
Normal file
53
spec/lib/activitypub/parser/custom_emoji_parser_spec.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::Parser::CustomEmojiParser do
|
||||
subject { described_class.new(json) }
|
||||
|
||||
context 'with fedibird license' do
|
||||
let(:json) do
|
||||
{
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: ['https://example.com/#foo'].join,
|
||||
name: 'ohagi',
|
||||
license: 'Ohagi is ohagi',
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
it 'load license' do
|
||||
expect(subject.license).to eq 'Ohagi is ohagi'
|
||||
end
|
||||
end
|
||||
|
||||
context 'with misskey license' do
|
||||
let(:json) do
|
||||
{
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: ['https://example.com/#foo'].join,
|
||||
name: 'ohagi',
|
||||
_misskey_license: {
|
||||
freeText: 'Ohagi is ohagi',
|
||||
},
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
it 'load license' do
|
||||
expect(subject.license).to eq 'Ohagi is ohagi'
|
||||
end
|
||||
end
|
||||
|
||||
context 'without license' do
|
||||
let(:json) do
|
||||
{
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: ['https://example.com/#foo'].join,
|
||||
name: 'ohagi',
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
it 'do not load license' do
|
||||
expect(subject.license).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
33
spec/serializers/activitypub/emoji_serializer_spec.rb
Normal file
33
spec/serializers/activitypub/emoji_serializer_spec.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::EmojiSerializer do
|
||||
describe '.serializer_for' do
|
||||
subject { serialized_record_json(model, described_class, adapter: ActivityPub::Adapter) }
|
||||
|
||||
let(:model) { Fabricate(:custom_emoji) }
|
||||
|
||||
context 'without license' do
|
||||
it 'does not have information' do
|
||||
expect(subject).to_not include({
|
||||
'_misskey_license' => { 'freeText' => 'Ohagi' },
|
||||
})
|
||||
expect(subject).to_not include({
|
||||
'license' => 'Ohagi',
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
context 'with license' do
|
||||
let(:model) { Fabricate(:custom_emoji, license: 'Ohagi') }
|
||||
|
||||
it 'has information' do
|
||||
expect(subject).to include({
|
||||
'license' => 'Ohagi',
|
||||
'_misskey_license' => { 'freeText' => 'Ohagi' },
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue