diff options
author | Jenkins <jenkins@jenkins.ninjawedding.org> | 2018-03-09 00:17:17 +0000 |
---|---|---|
committer | Jenkins <jenkins@jenkins.ninjawedding.org> | 2018-03-09 00:17:17 +0000 |
commit | 447d7e612753d69f043e08ebb228b21e411c8b4a (patch) | |
tree | 80caebcff2b131898f620f89ad0858d44530d30f /app/serializers | |
parent | 43a9a781a443a6b9296431fbcc4285b3ca6a1a57 (diff) | |
parent | ff44b2e92d496c6027b20157fea6ebd885906bea (diff) |
Merge remote-tracking branch 'tootsuite/master' into glitchsoc/master
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/activitypub/actor_serializer.rb | 6 | ||||
-rw-r--r-- | app/serializers/activitypub/add_serializer.rb | 24 | ||||
-rw-r--r-- | app/serializers/activitypub/collection_serializer.rb | 2 | ||||
-rw-r--r-- | app/serializers/activitypub/note_serializer.rb | 9 | ||||
-rw-r--r-- | app/serializers/activitypub/outbox_serializer.rb | 8 | ||||
-rw-r--r-- | app/serializers/activitypub/remove_serializer.rb | 24 | ||||
-rw-r--r-- | app/serializers/rest/instance_serializer.rb | 2 |
7 files changed, 72 insertions, 3 deletions
diff --git a/app/serializers/activitypub/actor_serializer.rb b/app/serializers/activitypub/actor_serializer.rb index 622bdde0c..afcd37771 100644 --- a/app/serializers/activitypub/actor_serializer.rb +++ b/app/serializers/activitypub/actor_serializer.rb @@ -4,7 +4,7 @@ class ActivityPub::ActorSerializer < ActiveModel::Serializer include RoutingHelper attributes :id, :type, :following, :followers, - :inbox, :outbox, + :inbox, :outbox, :featured, :preferred_username, :name, :summary, :url, :manually_approves_followers @@ -53,6 +53,10 @@ class ActivityPub::ActorSerializer < ActiveModel::Serializer account_outbox_url(object) end + def featured + account_collection_url(object, :featured) + end + def endpoints object end diff --git a/app/serializers/activitypub/add_serializer.rb b/app/serializers/activitypub/add_serializer.rb new file mode 100644 index 000000000..c0906e8d0 --- /dev/null +++ b/app/serializers/activitypub/add_serializer.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class ActivityPub::AddSerializer < ActiveModel::Serializer + include RoutingHelper + + attributes :type, :actor, :target + attribute :proper_object, key: :object + + def type + 'Add' + end + + def actor + ActivityPub::TagManager.instance.uri_for(object.account) + end + + def proper_object + ActivityPub::TagManager.instance.uri_for(object) + end + + def target + account_collection_url(object.account, :featured) + end +end diff --git a/app/serializers/activitypub/collection_serializer.rb b/app/serializers/activitypub/collection_serializer.rb index d43af3f8e..1ae492945 100644 --- a/app/serializers/activitypub/collection_serializer.rb +++ b/app/serializers/activitypub/collection_serializer.rb @@ -2,7 +2,7 @@ class ActivityPub::CollectionSerializer < ActiveModel::Serializer def self.serializer_for(model, options) - return ActivityPub::ActivitySerializer if model.class.name == 'Status' + return ActivityPub::NoteSerializer if model.class.name == 'Status' return ActivityPub::CollectionSerializer if model.class.name == 'ActivityPub::CollectionPresenter' super end diff --git a/app/serializers/activitypub/note_serializer.rb b/app/serializers/activitypub/note_serializer.rb index 24c39f3c9..d0e6290c1 100644 --- a/app/serializers/activitypub/note_serializer.rb +++ b/app/serializers/activitypub/note_serializer.rb @@ -90,6 +90,7 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer include RoutingHelper attributes :type, :media_type, :url, :name + attribute :focal_point, if: :focal_point? def type 'Document' @@ -106,6 +107,14 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer def url object.local? ? full_asset_url(object.file.url(:original, false)) : object.remote_url end + + def focal_point? + object.file.meta.is_a?(Hash) && object.file.meta['focus'].is_a?(Hash) + end + + def focal_point + [object.file.meta['focus']['x'], object.file.meta['focus']['y']] + end end class MentionSerializer < ActiveModel::Serializer diff --git a/app/serializers/activitypub/outbox_serializer.rb b/app/serializers/activitypub/outbox_serializer.rb new file mode 100644 index 000000000..48fbad0fd --- /dev/null +++ b/app/serializers/activitypub/outbox_serializer.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class ActivityPub::OutboxSerializer < ActivityPub::CollectionSerializer + def self.serializer_for(model, options) + return ActivityPub::ActivitySerializer if model.is_a?(Status) + super + end +end diff --git a/app/serializers/activitypub/remove_serializer.rb b/app/serializers/activitypub/remove_serializer.rb new file mode 100644 index 000000000..c2a5ae1b3 --- /dev/null +++ b/app/serializers/activitypub/remove_serializer.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class ActivityPub::RemoveSerializer < ActiveModel::Serializer + include RoutingHelper + + attributes :type, :actor, :target + attribute :proper_object, key: :object + + def type + 'Remove' + end + + def actor + ActivityPub::TagManager.instance.uri_for(object.account) + end + + def proper_object + ActivityPub::TagManager.instance.uri_for(object) + end + + def target + account_collection_url(object.account, :featured) + end +end diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index 0168b18ea..cab05e60a 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -52,7 +52,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer end def languages - [ENV.fetch('DEFAULT_LOCALE', I18n.default_locale)] + [I18n.default_locale] end private |