Skip to content

Commit

Permalink
Add endorsement to actor serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
noellabo committed Apr 3, 2019
1 parent 1205440 commit 08b61c3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
56 changes: 56 additions & 0 deletions app/controllers/endorsement_accounts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true

class EndorsementAccountsController < ApplicationController
include AccountControllerConcern

def index
respond_to do |format|
format.html do
next if @account.user_hides_network?

endorsed
@relationships = AccountRelationshipsPresenter.new(endorsed.map(&:target_account_id), current_user.account_id) if user_signed_in?
end

format.json do
raise Mastodon::NotPermittedError if params[:page].present? && @account.user_hides_network?

render json: collection_presenter,
serializer: ActivityPub::CollectionSerializer,
adapter: ActivityPub::Adapter,
content_type: 'application/activity+json'
end
end
end

private

def endorsed
@endorsed ||= AccountPin.where(account: @account).page(params[:page]).per(FOLLOW_PER_PAGE).preload(:target_account)
end

def page_url(page)
account_endorsed_index_path(@account, page: page) unless page.nil?
end

def collection_presenter
if params[:page].present?
ActivityPub::CollectionPresenter.new(
id: account_endorsed_index_path(@account, page: params.fetch(:page, 1)),
type: :ordered,
size: endorsed.count,
items: endorsed.map { |f| ActivityPub::TagManager.instance.uri_for(f.target_account) },
part_of: account_endorsed_index_path(@account),
next: page_url(endorsed.next_page),
prev: page_url(endorsed.prev_page)
)
else
ActivityPub::CollectionPresenter.new(
id: account_endorsed_index_path(@account),
type: :ordered,
size: endorsed.count,
first: page_url(1)
)
end
end
end
6 changes: 5 additions & 1 deletion app/serializers/activitypub/actor_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
context_extensions :manually_approves_followers, :featured, :also_known_as,
:moved_to, :property_value, :hashtag, :emoji, :identity_proof

attributes :id, :type, :following, :followers,
attributes :id, :type, :following, :followers, :endorsed,
:inbox, :outbox, :featured,
:preferred_username, :name, :summary,
:url, :manually_approves_followers
Expand Down Expand Up @@ -54,6 +54,10 @@ def followers
account_followers_url(object)
end

def endorsed
account_endorsed_index_url(object)
end

def inbox
account_inbox_url(object)
end
Expand Down
18 changes: 18 additions & 0 deletions app/views/endorsement_accounts/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
- content_for :page_title do
= t('accounts.people_followed_by', name: display_name(@account))

- content_for :header_tags do
%meta{ name: 'robots', content: 'noindex' }/
= render 'accounts/og', account: @account, url: account_followers_url(@account, only_path: false)

= render 'accounts/header', account: @account

- if @account.user_hides_network?
.nothing-here= t('accounts.network_hidden')
- elsif @endorsed.empty?
= nothing_here
- else
.card-grid
= render partial: 'application/card', collection: @endorsed.map(&:target_account), as: :account

= paginate @endorsed
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

resources :followers, only: [:index], controller: :follower_accounts
resources :following, only: [:index], controller: :following_accounts
resources :endorsed, only: [:index], controller: :endorsement_accounts
resource :follow, only: [:create], controller: :account_follow
resource :unfollow, only: [:create], controller: :account_unfollow

Expand Down

0 comments on commit 08b61c3

Please sign in to comment.