2017-07-15 02:01:39 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ActivityPub::Adapter < ActiveModelSerializers::Adapter::Base
|
2017-09-02 13:01:23 +01:00
|
|
|
CONTEXT = {
|
|
|
|
'@context': [
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
|
|
|
|
{
|
2017-09-02 22:13:35 +01:00
|
|
|
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
|
|
|
'sensitive' => 'as:sensitive',
|
2018-07-30 18:33:37 +01:00
|
|
|
'movedTo' => { '@id' => 'as:movedTo', '@type' => '@id' },
|
2018-12-29 01:24:36 +00:00
|
|
|
'alsoKnownAs' => { '@id' => 'as:alsoKnownAs', '@type' => '@id' },
|
2017-09-02 22:13:35 +01:00
|
|
|
'Hashtag' => 'as:Hashtag',
|
|
|
|
'ostatus' => 'http://ostatus.org#',
|
|
|
|
'atomUri' => 'ostatus:atomUri',
|
|
|
|
'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri',
|
|
|
|
'conversation' => 'ostatus:conversation',
|
2017-09-19 04:05:48 +01:00
|
|
|
'toot' => 'http://joinmastodon.org/ns#',
|
|
|
|
'Emoji' => 'toot:Emoji',
|
2018-02-21 23:35:46 +00:00
|
|
|
'focalPoint' => { '@container' => '@list', '@id' => 'toot:focalPoint' },
|
2018-07-30 18:33:37 +01:00
|
|
|
'featured' => { '@id' => 'toot:featured', '@type' => '@id' },
|
2018-04-14 11:41:08 +01:00
|
|
|
'schema' => 'http://schema.org#',
|
|
|
|
'PropertyValue' => 'schema:PropertyValue',
|
|
|
|
'value' => 'schema:value',
|
2017-09-02 13:01:23 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
}.freeze
|
|
|
|
|
2017-07-15 02:01:39 +01:00
|
|
|
def self.default_key_transform
|
|
|
|
:camel_lower
|
|
|
|
end
|
|
|
|
|
2017-08-12 16:41:03 +01:00
|
|
|
def self.transform_key_casing!(value, _options)
|
|
|
|
ActivityPub::CaseTransform.camel_lower(value)
|
|
|
|
end
|
|
|
|
|
2017-07-15 02:01:39 +01:00
|
|
|
def serializable_hash(options = nil)
|
|
|
|
options = serialization_options(options)
|
2017-09-11 23:16:18 +01:00
|
|
|
serialized_hash = ActiveModelSerializers::Adapter::Attributes.new(serializer, instance_options).serializable_hash(options)
|
|
|
|
CONTEXT.merge(self.class.transform_key_casing!(serialized_hash, instance_options))
|
2017-07-15 02:01:39 +01:00
|
|
|
end
|
|
|
|
end
|