Eventually fetch actors in mentions
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
14545fd983
commit
852be15a3e
|
@ -8,8 +8,8 @@ defmodule Mobilizon.Service.Formatter do
|
||||||
Formats input text to structured data, extracts mentions and hashtags.
|
Formats input text to structured data, extracts mentions and hashtags.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.Actors
|
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
|
alias Mobilizon.Federation.ActivityPub.Actor, as: ActivityPubActor
|
||||||
alias Mobilizon.Service.Formatter.HTML
|
alias Mobilizon.Service.Formatter.HTML
|
||||||
alias Phoenix.HTML.Tag
|
alias Phoenix.HTML.Tag
|
||||||
|
|
||||||
|
@ -22,26 +22,26 @@ defmodule Mobilizon.Service.Formatter do
|
||||||
|
|
||||||
@spec escape_mention_handler(String.t(), String.t(), any(), any()) :: String.t()
|
@spec escape_mention_handler(String.t(), String.t(), any(), any()) :: String.t()
|
||||||
defp escape_mention_handler("@" <> nickname = mention, buffer, _, _) do
|
defp escape_mention_handler("@" <> nickname = mention, buffer, _, _) do
|
||||||
case Actors.get_actor_by_name(nickname) do
|
case ActivityPubActor.find_or_make_actor_from_nickname(nickname) do
|
||||||
%Actor{} ->
|
{:ok, %Actor{}} ->
|
||||||
# escape markdown characters with `\\`
|
# escape markdown characters with `\\`
|
||||||
# (we don't want something like @user__name to be parsed by markdown)
|
# (we don't want something like @user__name to be parsed by markdown)
|
||||||
String.replace(mention, @markdown_characters_regex, "\\\\\\1")
|
String.replace(mention, @markdown_characters_regex, "\\\\\\1")
|
||||||
|
|
||||||
nil ->
|
{:error, _err} ->
|
||||||
buffer
|
buffer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec mention_handler(String.t(), String.t(), any(), map()) :: {String.t(), map()}
|
@spec mention_handler(String.t(), String.t(), any(), map()) :: {String.t(), map()}
|
||||||
def mention_handler("@" <> nickname, buffer, _opts, acc) do
|
def mention_handler("@" <> nickname, buffer, _opts, acc) do
|
||||||
case Actors.get_actor_by_name(nickname) do
|
case ActivityPubActor.find_or_make_actor_from_nickname(nickname) do
|
||||||
# %Actor{preferred_username: preferred_username} = actor ->
|
# %Actor{preferred_username: preferred_username} = actor ->
|
||||||
# link = "<span class='h-card mention'>@<span>#{preferred_username}</span></span>"
|
# link = "<span class='h-card mention'>@<span>#{preferred_username}</span></span>"
|
||||||
#
|
#
|
||||||
# {link, %{acc | mentions: MapSet.put(acc.mentions, {"@" <> nickname, actor})}}
|
# {link, %{acc | mentions: MapSet.put(acc.mentions, {"@" <> nickname, actor})}}
|
||||||
|
|
||||||
%Actor{type: :Person, id: id, preferred_username: preferred_username} = actor ->
|
{:ok, %Actor{type: :Person, id: id, preferred_username: preferred_username} = actor} ->
|
||||||
# link =
|
# link =
|
||||||
# "<span class='h-card mention' data-user='#{id}'>@<span>#{preferred_username}</span></span>"
|
# "<span class='h-card mention' data-user='#{id}'>@<span>#{preferred_username}</span></span>"
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ defmodule Mobilizon.Service.Formatter do
|
||||||
|
|
||||||
{link, %{acc | mentions: MapSet.put(acc.mentions, {"@" <> nickname, actor})}}
|
{link, %{acc | mentions: MapSet.put(acc.mentions, {"@" <> nickname, actor})}}
|
||||||
|
|
||||||
nil ->
|
{:error, _} ->
|
||||||
{buffer, acc}
|
{buffer, acc}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue