Browse Source

Add searching for remote statuses

master
Shadowfacts 1 year ago
parent
commit
a0e290197f
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
6 changed files with 57 additions and 3 deletions
  1. +10
    -0
      assets/css/clacks.scss
  2. +2
    -2
      lib/clacks/activitypub/fetcher.ex
  3. +31
    -0
      lib/clacks_web/controllers/frontend_controller.ex
  4. +1
    -1
      lib/clacks_web/router.ex
  5. +12
    -0
      lib/clacks_web/templates/frontend/search.html.eex
  6. +1
    -0
      lib/clacks_web/templates/layout/app.html.eex

+ 10
- 0
assets/css/clacks.scss 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;
}
}

+ 2
- 2
lib/clacks/activitypub/fetcher.ex 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
_ ->


+ 31
- 0
lib/clacks_web/controllers/frontend_controller.ex 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)


+ 1
- 1
lib/clacks_web/router.ex 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


+ 12
- 0
lib/clacks_web/templates/frontend/search.html.eex 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 %>

+ 1
- 0
lib/clacks_web/templates/layout/app.html.eex 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 %>


Loading…
Cancel
Save