Add searching for remote actors

This commit is contained in:
Shadowfacts 2020-04-26 16:15:20 -04:00
parent e7c19940b0
commit e7dcbdc6a4
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 35 additions and 4 deletions

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

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 %>