Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ActivityPub actor representations #1239

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ gem "haml", "~> 6.1"
gem "hcaptcha", "~> 7.0"
gem "mini_magick"
gem "oj"
gem "panko_serializer"
gem "rpush"
gem "rqrcode"

Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ GEM
oj (3.15.0)
openssl (3.1.0)
orm_adapter (0.5.0)
panko_serializer (0.8.0)
activesupport
oj (> 3.11.0, < 4.0.0)
parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1)
Expand Down Expand Up @@ -523,6 +526,7 @@ DEPENDENCIES
net-smtp
oj
openssl (~> 3.1)
panko_serializer
pg
pghero
prometheus-client (~> 4.1)
Expand Down
7 changes: 5 additions & 2 deletions app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ class UserController < ApplicationController
after_action :mark_notification_as_read, only: %i[show]

def show
@pinned_answers = @user.answers.pinned.order(pinned_at: :desc).limit(10)
paginate_answers { |args| @user.cursored_answers(**args) }
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

Expand Down
10 changes: 10 additions & 0 deletions app/serializers/image_serializer.rb
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions app/serializers/user_serializer.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@
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"
Expand Down