Skip to content

Commit

Permalink
move creator presentation code into presenter
Browse files Browse the repository at this point in the history
  • Loading branch information
Floppy committed Jan 28, 2025
1 parent c60b2f0 commit 832f079
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
22 changes: 1 addition & 21 deletions app/models/creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ def self.find_param(param)
find_by!(slug: param)
end

def summary_html
return unless caption || notes
"<section>#{"<header>#{caption}</header>" if caption}#{Kramdown::Document.new(notes).to_html.rstrip if notes}</section>"
end

def self.create_from_activitypub_object(actor)
matches = actor.extensions["summary"].match(/<section><header>(.+)<\/header><p>(.+)<\/p><\/section>/)
create(
Expand All @@ -45,21 +40,6 @@ def self.create_from_activitypub_object(actor)
end

def to_activitypub_object
{
"@context": {
f3di: "http://purl.org/f3di/ns#",
toot: "http://joinmastodon.org/ns#",
attributionDomains: {
"@id": "toot:attributionDomains",
"@type": "@id"
}
},
summary: summary_html,
attributionDomains: [
[Rails.application.default_url_options[:host], Rails.application.default_url_options[:port]].compact.join(":")
],
"f3di:concreteType": "Creator",
attachment: links.map { |it| {type: "Link", href: it.url} }
}
ActivityPub::CreatorPresenter.new(self).present!
end
end
46 changes: 46 additions & 0 deletions app/presenters/activity_pub/creator_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module ActivityPub
class CreatorPresenter < BasePresenter
def present!
{
"@context": {
f3di: "http://purl.org/f3di/ns#",
toot: "http://joinmastodon.org/ns#",
attributionDomains: {
"@id": "toot:attributionDomains",
"@type": "@id"
}
},
summary: summary_html,
attributionDomains: [
[Rails.application.default_url_options[:host], Rails.application.default_url_options[:port]].compact.join(":")
],
"f3di:concreteType": "Creator",
attachment: @object.links.map { |it| {type: "Link", href: it.url} }
}.merge(address_fields)
end

def federate?
# Currently unused
public?
end

def to
PUBLIC_COLLECTION if public?
end

def cc
@object.federails_actor.followers_url
end

private

def public?
CreatorPolicy.new(nil, @object).show?
end

def summary_html
return unless @object.caption || @object.notes
"<section>#{"<header>#{@object.caption}</header>" if @object.caption}#{Kramdown::Document.new(@object.notes).to_html.rstrip if @object.notes}</section>"
end
end
end

0 comments on commit 832f079

Please sign in to comment.