diff --git a/app/controllers/activitypub/collections_controller.rb b/app/controllers/activitypub/collections_controller.rb index 989fee385d116e4f27ada0763e20554a910d9f27..a3dade822bcf84f981dc95d12e1d5cebe20477a1 100644 --- a/app/controllers/activitypub/collections_controller.rb +++ b/app/controllers/activitypub/collections_controller.rb @@ -7,11 +7,13 @@ class ActivityPub::CollectionsController < ActivityPub::BaseController before_action :require_signature!, if: :authorized_fetch_mode? before_action :set_size before_action :set_statuses + before_action :set_featured_tags + before_action :set_endorsed_accounts before_action :set_cache_headers def show expires_in 3.minutes, public: public_fetch_mode? - render_with_cache json: collection_presenter, content_type: 'application/activity+json', serializer: ActivityPub::CollectionSerializer, adapter: ActivityPub::Adapter, skip_activities: true + render_with_cache json: collection_presenter, content_type: 'application/activity+json', serializer: ActivityPub::CollectionSerializer, adapter: ActivityPub::Adapter end private @@ -21,10 +23,18 @@ class ActivityPub::CollectionsController < ActivityPub::BaseController @statuses = cache_collection(@statuses, Status) end + def set_featured_tags + @featured_tags = @account.featured_tags + end + + def set_endorsed_accounts + @endorsed_accounts = @account.endorsed_accounts + end + def set_size case params[:id] when 'featured' - @account.pinned_statuses.count + @account.pinned_statuses.count + @account.featured_tags.count + @account.account_pins.count else raise ActiveRecord::RecordNotFound end @@ -46,7 +56,7 @@ class ActivityPub::CollectionsController < ActivityPub::BaseController id: account_collection_url(@account, params[:id]), type: :ordered, size: @size, - items: @statuses + items: @statuses + @featured_tags + @endorsed_accounts ) end end diff --git a/app/serializers/activitypub/collection_serializer.rb b/app/serializers/activitypub/collection_serializer.rb index da1ba735fc25063c69c83e4aedb88796ce7ed55d..38c4980807dd71770e6bfe2b65a20df5dd8646cd 100644 --- a/app/serializers/activitypub/collection_serializer.rb +++ b/app/serializers/activitypub/collection_serializer.rb @@ -2,9 +2,18 @@ class ActivityPub::CollectionSerializer < ActivityPub::Serializer def self.serializer_for(model, options) - return ActivityPub::NoteSerializer if model.class.name == 'Status' - return ActivityPub::CollectionSerializer if model.class.name == 'ActivityPub::CollectionPresenter' - super + case model.class.name + when 'Status' + ActivityPub::NoteSerializer + when 'FeaturedTag' + ActivityPub::HashtagSerializer + when 'Account' + ActivityPub::MentionSerializer + when 'ActivityPub::CollectionPresenter' + ActivityPub::CollectionSerializer + else + super + end end attribute :id, if: -> { object.id.present? } diff --git a/app/serializers/activitypub/hashtag_serializer.rb b/app/serializers/activitypub/hashtag_serializer.rb new file mode 100644 index 0000000000000000000000000000000000000000..1a56e4dfe4c745f375bacb3b6001d7b6d8d95291 --- /dev/null +++ b/app/serializers/activitypub/hashtag_serializer.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class ActivityPub::HashtagSerializer < ActivityPub::Serializer + include RoutingHelper + + attributes :type, :href, :name + + def type + 'Hashtag' + end + + def name + "##{object.name}" + end + + def href + if object.class.name == 'FeaturedTag' + short_account_tag_url(object.account, object.tag) + else + tag_url(object) + end + end +end diff --git a/app/serializers/activitypub/mention_serializer.rb b/app/serializers/activitypub/mention_serializer.rb new file mode 100644 index 0000000000000000000000000000000000000000..24bd570fe9fd920cc6d040c671a4576e91572132 --- /dev/null +++ b/app/serializers/activitypub/mention_serializer.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class ActivityPub::MentionSerializer < ActivityPub::Serializer + attributes :type, :href, :name + + def type + 'Mention' + end + + def href + ActivityPub::TagManager.instance.uri_for(object) + end + + def name + "@#{object.acct}" + end +end