Skip to content

Commit

Permalink
Merge pull request #3478 from manyfold3d/remote-creators
Browse files Browse the repository at this point in the history
Include followed remote creators in list
  • Loading branch information
Floppy authored Jan 23, 2025
2 parents 80b9e18 + 7fcf5cb commit 466fe90
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ gem "better_content_security_policy", "~> 0.1.4"
gem "devise_zxcvbn", "~> 6.0"

gem "ransack", "~> 4.2"
gem "federails", git: "https://gitlab.com/experimentslabs/federails", branch: "main"
gem "federails", git: "https://gitlab.com/experimentslabs/federails", branch: "avoid-double-create"
gem "federails-moderation", "~> 0.2"
gem "caber"

Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ GIT

GIT
remote: https://gitlab.com/experimentslabs/federails
revision: 6698571f51f886a5fd5ba6fb57221c55d4d4d3b4
branch: main
revision: 6ee94ba7ca869e543b55b0d568d412c5f90a788f
branch: avoid-double-create
specs:
federails (0.5.0)
faraday
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/follows_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def follow_remote_actor
authorize Federails::Following, :create?
@actor = Federails::Actor.find_param(params[:id])
current_user.follow(@actor)
# If the remote actor has a known Manyfold type, we can create a real object for it
find_or_create_entity(@actor)
redirect_to root_url, notice: t(".followed", actor: @actor.at_address)
end

Expand Down Expand Up @@ -76,4 +78,12 @@ def get_target
id = params[followable_param]
@target = policy_scope(followable).find_param(id)
end

def find_or_create_entity(actor)
return entity if actor.entity
case actor.extensions&.dig("concreteType")
when "Creator"
Creator.create_from_activitypub_object(actor)
end
end
end
4 changes: 4 additions & 0 deletions app/models/concerns/federails_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ def federails_actor
end
act
end

def remote?
!federails_actor&.local?
end
end
12 changes: 12 additions & 0 deletions app/models/creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ def summary_html
"<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(
name: actor.name,
slug: actor.username,
links_attributes: actor.extensions["attachment"]&.select { |it| it["type"] == "Link" }&.map { |it| {url: it["href"]} },
caption: matches[1],
notes: matches[2],
federails_actor: actor
)
end

def to_activitypub_object
{
"@context": {
Expand Down
14 changes: 11 additions & 3 deletions app/views/creators/_creator.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<div class="col mb-4">
<div class="card">
<div class="card-body">
<div class="card-title"><%= creator.name %></div>
<div class="card-title">
<%= icon "globe2", t(".distant") if creator.remote? %>
<%= creator.name %>
</div>
<% if creator.caption %>
<small class="card-subtitle mb-2 text-muted"><%= sanitize creator.caption %></small>
<% end %>
Expand All @@ -10,8 +13,13 @@
<li><%= link_to t("sites.%{site}" % {site: link.site}), link.url %></li>
<% end %>
</ul>
<%= link_to "#{policy_scope(Model).where(creator: creator).count} #{Model.model_name.human count: policy_scope(Model).where(creator: creator).count}", creator, {class: "btn btn-primary", "aria-label": translate(".models_button.label", name: creator.name)} if policy(creator).show? %>
<%= link_to icon("pencil-fill", t(".edit_button.text")), edit_creator_path(creator), {class: "btn btn-outline-secondary", "aria-label": translate(".edit_button.label", name: creator.name)} if policy(creator).edit? %>
<% if creator.remote? %>
<%= link_to "#{policy_scope(Model).where(creator: creator).count} #{Model.model_name.human count: policy_scope(Model).where(creator: creator).count}", creator, {class: "btn btn-primary", "aria-label": translate(".models_button.remote_label", name: creator.name)} if policy(creator).show? %>
<%= link_to icon("globe2", t(".visit_button.text")), creator.federails_actor.profile_url, {class: "btn btn-outline-secondary", "aria-label": translate(".visit_button.label", name: creator.name, target: "new")} %>
<% else %>
<%= link_to "#{policy_scope(Model).where(creator: creator).count} #{Model.model_name.human count: policy_scope(Model).where(creator: creator).count}", creator, {class: "btn btn-primary", "aria-label": translate(".models_button.label", name: creator.name)} if policy(creator).show? %>
<%= link_to icon("pencil-fill", t(".edit_button.text")), edit_creator_path(creator), {class: "btn btn-outline-secondary", "aria-label": translate(".edit_button.label", name: creator.name)} if policy(creator).edit? %>
<% end %>
</div>
</div>
</div>
13 changes: 11 additions & 2 deletions app/views/creators/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@
<div class="card-body row">
<div class="col col-auto">
<%= content_tag(:div, class: "text-center") do %>
<%= content_tag(:h2) { @creator.name } %>
<p><small class="text-secondary">@<%= @creator.federails_actor.at_address if SiteSettings.federation_enabled? %></small></p>
<h2>
<%= icon "globe2", t(".distant") if @creator.remote? %>
<%= @creator.name %>
</h2>
<p>
<% if @creator.remote? %>
<small class="text-secondary"><%= link_to "@" + @creator.federails_actor.at_address, @creator.federails_actor.profile_url, target: "new" %></small>
<% else %>
<small class="text-secondary">@<%= @creator.federails_actor.at_address if SiteSettings.federation_enabled? %></small>
<% end %>
</p>
<%= render FollowButtonComponent.new(follower: current_user, target: @creator) %>
<% end %>
</div>
Expand Down
6 changes: 6 additions & 0 deletions config/locales/creators/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ en:
create:
success: New creator details saved.
creator:
distant: Remote creator
edit_button:
label: Edit creator %{name}
text: Edit
models_button:
label: Show models by %{name}
remote_label: Show local models by %{name}
visit_button:
label: Visit
text: Visit original profile
destroy:
success: Creator deleted!
form:
Expand All @@ -22,6 +27,7 @@ en:
index:
skip_creators: Skip creator list
show:
distant: Remote creator
edit: Edit Creator Profile
unassigned:
caption: All the models without a known creator.
Expand Down

0 comments on commit 466fe90

Please sign in to comment.