Add searching for remote statuses
This commit is contained in:
parent
b034d159a9
commit
a0e290197f
|
@ -151,3 +151,13 @@ ul.status-list {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.search-form {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
input[type=text] {
|
||||||
|
flex-grow: 1;
|
||||||
|
margin-right: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ defmodule Clacks.ActivityPub.Fetcher do
|
||||||
|
|
||||||
with %{"type" => type, "id" => remote_id} = actor <- fetch(id),
|
with %{"type" => type, "id" => remote_id} = actor <- fetch(id),
|
||||||
"person" <- String.downcase(type),
|
"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
|
actor
|
||||||
else
|
else
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -20,7 +20,7 @@ defmodule Clacks.ActivityPub.Fetcher do
|
||||||
%{host: id_host} = URI.parse(id)
|
%{host: id_host} = URI.parse(id)
|
||||||
|
|
||||||
with %{"actor" => remote_actor} = object <- fetch(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
|
object
|
||||||
else
|
else
|
||||||
_ ->
|
_ ->
|
||||||
|
|
|
@ -132,6 +132,37 @@ defmodule ClacksWeb.FrontendController do
|
||||||
end
|
end
|
||||||
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
|
def post_status(conn, %{"content" => content} = params) do
|
||||||
current_user = conn.assigns[:user] |> Repo.preload(:actor)
|
current_user = conn.assigns[:user] |> Repo.preload(:actor)
|
||||||
|
|
||||||
|
|
|
@ -58,8 +58,8 @@ defmodule ClacksWeb.Router do
|
||||||
pipe_through :browser_authenticated
|
pipe_through :browser_authenticated
|
||||||
|
|
||||||
post "/post", FrontendController, :post_status
|
post "/post", FrontendController, :post_status
|
||||||
|
|
||||||
get "/status/:id/reply", FrontendController, :reply
|
get "/status/:id/reply", FrontendController, :reply
|
||||||
|
get "/search", FrontendController, :search
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/", ClacksWeb do
|
scope "/", ClacksWeb do
|
||||||
|
|
|
@ -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 %>
|
|
@ -13,6 +13,7 @@
|
||||||
<nav role="navigation">
|
<nav role="navigation">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/"><%= instance_name() %></a></li>
|
<li><a href="/"><%= instance_name() %></a></li>
|
||||||
|
<li><a href="<%= Routes.frontend_path(@conn, :search) %>">Search</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul>
|
<ul>
|
||||||
<%= if @conn.assigns[:user] do %>
|
<%= if @conn.assigns[:user] do %>
|
||||||
|
|
Loading…
Reference in New Issue