Create ActivityPub actor representation of users

This commit is contained in:
Karina Kwiatek 2023-06-16 21:03:11 +02:00
parent c028ec1fa6
commit 1837d4a6b0
4 changed files with 36 additions and 2 deletions

View file

@ -8,12 +8,15 @@ class UserController < ApplicationController
after_action :mark_notification_as_read, only: %i[show]
def show
unless request.format == Mime[:json]
@pinned_answers = @user.answers.pinned.order(pinned_at: :desc).limit(10)
paginate_answers { |args| @user.cursored_answers(**args) }
end
respond_to do |format|
format.html
format.turbo_stream { render layout: false }
format.json { render json: UserSerializer.new(context: { controller: self }).serialize_to_json(@user) }
end
end

View file

@ -0,0 +1,10 @@
# frozen_string_literal: true
class ImageSerializer < Panko::Serializer
attributes :type, :url, :mime
aliases mime: "mediaType"
def type = "Image"
def mime = object.content_type
def url = object.url
end

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
class UserSerializer < Panko::Serializer
attributes :id, :type, :name, :url, :summary
aliases document_context: :@context
aliases created_at: :published
aliases screen_name: "preferredUsername"
has_one :profile_picture, serializer: ImageSerializer, name: :icon
has_one :profile_header, serializer: ImageSerializer, name: :image
def document_context = %w[https://www.w3.org/ns/activitystreams]
def id = context[:controller].activitypub_user_url(object)
def url = context[:controller].user_url(object)
def type = "Person"
def name = object.profile.display_name
def summary = object.profile.description
end

View file

@ -171,6 +171,8 @@ Rails.application.routes.draw do
get "/feedback/bugs(/*any)", to: "feedback#bugs", as: "feedback_bugs"
get "/feedback/feature_requests(/*any)", to: "feedback#features", as: "feedback_features"
get "/users/:username", to: "user#show", as: "activitypub_user", defaults: { format: :json }
namespace :well_known, path: "/.well-known" do
get "/change-password", to: redirect("/settings/account")
get "/nodeinfo", to: "node_info#discovery"