diff --git a/lib/clacks_web/templates/frontend/status.html.eex b/lib/clacks_web/templates/frontend/status.html.eex index 07833a4..51178d5 100644 --- a/lib/clacks_web/templates/frontend/status.html.eex +++ b/lib/clacks_web/templates/frontend/status.html.eex @@ -4,7 +4,7 @@ <%= form_tag Routes.frontend_path(@conn, :post_status), method: :post, class: "compose-status" do %> "> - + <%= submit "Post" %>
<% end %> diff --git a/lib/clacks_web/views/frontend_view.ex b/lib/clacks_web/views/frontend_view.ex index a11439a..0a846dc 100644 --- a/lib/clacks_web/views/frontend_view.ex +++ b/lib/clacks_web/views/frontend_view.ex @@ -1,6 +1,6 @@ defmodule ClacksWeb.FrontendView do use ClacksWeb, :view - alias Clacks.{Actor, Activity} + alias Clacks.{Actor, Activity, Repo} alias ClacksWeb.Router.Helpers, as: Routes alias ClacksWeb.Endpoint @@ -88,4 +88,36 @@ defmodule ClacksWeb.FrontendView do defp activity_id(%Activity{id: id}), do: id defp activity_id({%Activity{id: id}, _}), do: id + + @spec mentions_for_replying_to(Activity.t()) :: String.t() + defp mentions_for_replying_to(conn, %Activity{ + data: %{"object" => %{"actor" => actor, "tag" => tags}} + }) do + current_user = conn.assigns[:user] |> Repo.preload(:actor) + + tag_actors = + tags + |> Enum.filter(fn + %{"type" => "Mention"} -> true + _ -> false + end) + |> Enum.map(fn %{"href" => ap_id} -> ap_id end) + + actors = + [actor | tag_actors] + |> List.delete(current_user.actor.ap_id) + |> Enum.uniq() + + mentions = + actors + |> Enum.map(fn ap_id -> + actor = Actor.get_cached_by_ap_id(ap_id) + "@#{actor.nickname}" + end) + |> Enum.join(" ") + + "#{mentions} " + end + + defp mentions_for_replying_to(_), do: "" end