Browse Source

Add mentions to status reply textarea

master
Shadowfacts 1 year ago
parent
commit
a2ddde09f7
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
2 changed files with 34 additions and 2 deletions
  1. +1
    -1
      lib/clacks_web/templates/frontend/status.html.eex
  2. +33
    -1
      lib/clacks_web/views/frontend_view.ex

+ 1
- 1
lib/clacks_web/templates/frontend/status.html.eex View File

@ -4,7 +4,7 @@
<%= 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"] %>">
<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" %>
<hr>
<% end %>

+ 33
- 1
lib/clacks_web/views/frontend_view.ex View File

@ -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

Loading…
Cancel
Save