Add mentions to status reply textarea
This commit is contained in:
parent
90a653d059
commit
a2ddde09f7
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
<%= form_tag Routes.frontend_path(@conn, :post_status), method: :post, class: "compose-status" do %>
|
<%= form_tag Routes.frontend_path(@conn, :post_status), method: :post, class: "compose-status" do %>
|
||||||
<input type="hidden" name="in_reply_to" value="<%= @status.data["object"]["id"] %>">
|
<input type="hidden" name="in_reply_to" value="<%= @status.data["object"]["id"] %>">
|
||||||
<textarea id="content" name="content" rows="5" placeholder="Reply" required></textarea>
|
<textarea id="content" name="content" rows="5" placeholder="Reply" required><%= mentions_for_replying_to(@conn, @status) %></textarea>
|
||||||
<%= submit "Post" %>
|
<%= submit "Post" %>
|
||||||
<hr>
|
<hr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
defmodule ClacksWeb.FrontendView do
|
defmodule ClacksWeb.FrontendView do
|
||||||
use ClacksWeb, :view
|
use ClacksWeb, :view
|
||||||
alias Clacks.{Actor, Activity}
|
alias Clacks.{Actor, Activity, Repo}
|
||||||
alias ClacksWeb.Router.Helpers, as: Routes
|
alias ClacksWeb.Router.Helpers, as: Routes
|
||||||
alias ClacksWeb.Endpoint
|
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
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue