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

Include creator caption and notes in activitystream summary #3473

Merged
merged 1 commit into from
Jan 22, 2025
Merged
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
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
Loading