diff --git a/assets/css/clacks.scss b/assets/css/clacks.scss index c653a9c..9df9e81 100644 --- a/assets/css/clacks.scss +++ b/assets/css/clacks.scss @@ -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; + } +} diff --git a/lib/clacks/activitypub/fetcher.ex b/lib/clacks/activitypub/fetcher.ex index 0389b2b..cff52ff 100644 --- a/lib/clacks/activitypub/fetcher.ex +++ b/lib/clacks/activitypub/fetcher.ex @@ -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 _ -> diff --git a/lib/clacks_web/controllers/frontend_controller.ex b/lib/clacks_web/controllers/frontend_controller.ex index 2f945ed..2a9bd68 100644 --- a/lib/clacks_web/controllers/frontend_controller.ex +++ b/lib/clacks_web/controllers/frontend_controller.ex @@ -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) diff --git a/lib/clacks_web/router.ex b/lib/clacks_web/router.ex index 45dc602..bcdf092 100644 --- a/lib/clacks_web/router.ex +++ b/lib/clacks_web/router.ex @@ -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 diff --git a/lib/clacks_web/templates/frontend/search.html.eex b/lib/clacks_web/templates/frontend/search.html.eex new file mode 100644 index 0000000..46d111e --- /dev/null +++ b/lib/clacks_web/templates/frontend/search.html.eex @@ -0,0 +1,12 @@ +<%= form_tag Routes.frontend_path(@conn, :search), method: :get, class: "search-form" do %> + + <%= submit "Search" %> +<% end %> + +<%= if @conn.assigns[:status_results] do %> +
+ + <%= for {status, author} <- @status_results do %> + <%= render "_status.html", conn: @conn, author: author, status: status, note: status.data["object"] %> + <% end %> +<% end %> diff --git a/lib/clacks_web/templates/layout/app.html.eex b/lib/clacks_web/templates/layout/app.html.eex index c2e5d0a..6b4c291 100644 --- a/lib/clacks_web/templates/layout/app.html.eex +++ b/lib/clacks_web/templates/layout/app.html.eex @@ -13,6 +13,7 @@