Skip to content

Commit

Permalink
Merge pull request #3473 from manyfold3d/as-summary
Browse files Browse the repository at this point in the history
Include creator caption and notes in activitystream summary
  • Loading branch information
Floppy authored Jan 22, 2025
2 parents 738a5f5 + 8ac70bf commit f598be9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ 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 to_activitypub_object
{
"@context": {
Expand All @@ -41,6 +46,7 @@ def to_activitypub_object
"@type": "@string"
}
},
summary: summary_html,
attributionDomains: [
[Rails.application.default_url_options[:host], Rails.application.default_url_options[:port]].compact.join(":")
],
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
factory :creator do
sequence(:name) { |n| "Creator #{n}" }
sequence(:public_id) { |n| "creator_#{n}" }
caption { Faker::Lorem.sentence }
notes { Faker::Lorem.paragraph }
end
end
22 changes: 22 additions & 0 deletions spec/models/creator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,26 @@
it_behaves_like "Commentable"
it_behaves_like "Caber::Object"
it_behaves_like "Sluggable"

context "when generating an ActivityStreams representation" do
subject(:creator) { create(:creator) }

let(:ap) { creator.to_activitypub_object }

it "includes concrete type" do
expect(ap[:concreteType]).to eq "Creator"
end

it "includes attributionDomain" do
expect(ap[:attributionDomains]).to eq ["localhost:3214"]
end

it "includes caption in summary" do
expect(ap[:summary]).to include creator.caption
end

it "includes notes in summary" do
expect(ap[:summary]).to include creator.notes
end
end
end

0 comments on commit f598be9

Please sign in to comment.