Add searching for remote statuses

This commit is contained in:
Shadowfacts 2020-04-25 22:28:30 -04:00
parent b034d159a9
commit a0e290197f
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
6 changed files with 57 additions and 3 deletions

View File

@ -151,3 +151,13 @@ ul.status-list {
box-sizing: border-box;
}
}
.search-form {
width: 100%;
display: flex;
input[type=text] {
flex-grow: 1;
margin-right: 1rem;
}
}

View File

@ -7,7 +7,7 @@ defmodule Clacks.ActivityPub.Fetcher do
with %{"type" => type, "id" => remote_id} = actor <- fetch(id),
"person" <- String.downcase(type),
%{host: actor_host} when actor_host == id_host <- URI.parse(remote_id) do
%{host: ^id_host} <- URI.parse(remote_id) do
actor
else
_ ->
@ -20,7 +20,7 @@ defmodule Clacks.ActivityPub.Fetcher do
%{host: id_host} = URI.parse(id)
with %{"actor" => remote_actor} = object <- fetch(id),
%{host: actor_host} when actor_host == id_host <- URI.parse(remote_actor) do
%{host: ^id_host} <- URI.parse(remote_actor) do
object
else
_ ->

View File

@ -132,6 +132,37 @@ defmodule ClacksWeb.FrontendController do
end
end
def search(conn, %{"q" => q}) when is_binary(q) do
current_user = conn.assigns[:user]
status_results =
with %Activity{
actor: actor_id,
data: %{"type" => "Create", "object" => %{"type" => "Note"}}
} = activity <- Object.fetch(q, true, :activity) |> IO.inspect(),
actor <- Actor.get_by_ap_id(actor_id) do
[{activity, actor}]
else
_ ->
[]
end
render(conn, "search.html", %{
current_user: current_user,
q: q,
status_results: status_results
})
end
def search(conn, _params) do
current_user = conn.assigns[:user]
render(conn, "search.html", %{
current_user: current_user,
q: ""
})
end
def post_status(conn, %{"content" => content} = params) do
current_user = conn.assigns[:user] |> Repo.preload(:actor)

View File

@ -58,8 +58,8 @@ defmodule ClacksWeb.Router do
pipe_through :browser_authenticated
post "/post", FrontendController, :post_status
get "/status/:id/reply", FrontendController, :reply
get "/search", FrontendController, :search
end
scope "/", ClacksWeb do

View File

@ -0,0 +1,12 @@
<%= form_tag Routes.frontend_path(@conn, :search), method: :get, class: "search-form" do %>
<input type="text" name="q" id="q" placeholder="Search Query" value="<%= @q %>">
<%= submit "Search" %>
<% end %>
<%= if @conn.assigns[:status_results] do %>
<hr>
<%= for {status, author} <- @status_results do %>
<%= render "_status.html", conn: @conn, author: author, status: status, note: status.data["object"] %>
<% end %>
<% end %>

View File

@ -13,6 +13,7 @@
<nav role="navigation">
<ul>
<li><a href="/"><%= instance_name() %></a></li>
<li><a href="<%= Routes.frontend_path(@conn, :search) %>">Search</a></li>
</ul>
<ul>
<%= if @conn.assigns[:user] do %>