Browse Source

Add searching for remote actors

master
Shadowfacts 1 year ago
parent
commit
e7dcbdc6a4
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
2 changed files with 35 additions and 4 deletions
  1. +15
    -3
      lib/clacks_web/controllers/frontend_controller.ex
  2. +20
    -1
      lib/clacks_web/templates/frontend/search.html.eex

+ 15
- 3
lib/clacks_web/controllers/frontend_controller.ex View File

@ -151,11 +151,20 @@ defmodule ClacksWeb.FrontendController do
def search(conn, %{"q" => q}) when is_binary(q) do
current_user = conn.assigns[:user]
actor_results =
case Actor.fetch(q) do
%Actor{} = actor ->
[actor]
_ ->
[]
end
status_results =
with %Activity{
actor: actor_id,
data: %{"type" => "Create", "object" => %{"type" => "Note"}}
} = activity <- Object.fetch(q, true, :activity) |> IO.inspect(),
} = activity <- Object.fetch(q, true, :activity),
actor <- Actor.get_by_ap_id(actor_id) do
[{activity, actor}]
else
@ -166,7 +175,8 @@ defmodule ClacksWeb.FrontendController do
render(conn, "search.html", %{
current_user: current_user,
q: q,
status_results: status_results
status_results: status_results,
actor_results: actor_results
})
end
@ -175,7 +185,9 @@ defmodule ClacksWeb.FrontendController do
render(conn, "search.html", %{
current_user: current_user,
q: ""
q: "",
status_results: [],
actor_results: []
})
end


+ 20
- 1
lib/clacks_web/templates/frontend/search.html.eex View File

@ -3,7 +3,26 @@
<%= submit "Search" %>
<% end %>
<%= if @conn.assigns[:status_results] do %>
<%= if length(@actor_results) > 0 do %>
<hr>
<%= for actor <- @actor_results do %>
<div class="actor">
<h2 class="actor-nickname">
<a href="<%= local_actor_link(actor) %>">
<%= actor.data["preferredUsername"] %>
</a>
</h2>
<h3 class="actor-username">
<a href="<%= actor.ap_id %>">
<%= display_username(actor) %>
</a>
</h3>
</div>
<% end %>
<% end %>
<%= if length(@status_results) do %>
<hr>
<%= for {status, author} <- @status_results do %>


Loading…
Cancel
Save