Refactor adding tags to an event
Also refactor extracting tags from content, now uses Pleroma's Formatter Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -10,6 +10,8 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Event do
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events.Event, as: EventModel
|
||||
alias Mobilizon.Service.ActivityPub.Converter
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Tag
|
||||
|
||||
@behaviour Converter
|
||||
|
||||
@@ -19,7 +21,8 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Event do
|
||||
@impl Converter
|
||||
@spec as_to_model_data(map()) :: map()
|
||||
def as_to_model_data(object) do
|
||||
with {:ok, %Actor{id: actor_id}} <- Actors.get_actor_by_url(object["actor"]) do
|
||||
with {:ok, %Actor{id: actor_id}} <- Actors.get_actor_by_url(object["actor"]),
|
||||
tags <- fetch_tags(object["tag"]) do
|
||||
picture_id =
|
||||
with true <- Map.has_key?(object, "attachment"),
|
||||
%Picture{id: picture_id} <-
|
||||
@@ -43,11 +46,24 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Event do
|
||||
"begins_on" => object["begins_on"],
|
||||
"category" => object["category"],
|
||||
"url" => object["id"],
|
||||
"uuid" => object["uuid"]
|
||||
"uuid" => object["uuid"],
|
||||
"tags" => tags
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
defp fetch_tags(tags) do
|
||||
Enum.reduce(tags, [], fn tag, acc ->
|
||||
case Events.get_or_create_tag(tag) do
|
||||
{:ok, %Tag{} = tag} ->
|
||||
acc ++ [tag]
|
||||
|
||||
_ ->
|
||||
acc
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Convert an event struct to an ActivityStream representation
|
||||
"""
|
||||
|
||||
@@ -296,7 +296,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
"actor" => actor,
|
||||
"id" => Routes.page_url(Endpoint, :event, uuid),
|
||||
"uuid" => uuid,
|
||||
"tag" => tags |> Enum.map(fn {_, tag} -> tag end) |> Enum.uniq()
|
||||
"tag" => tags |> Enum.uniq()
|
||||
}
|
||||
|
||||
if is_nil(picture), do: res, else: Map.put(res, "attachment", [make_picture_data(picture)])
|
||||
@@ -328,7 +328,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
"actor" => actor,
|
||||
"id" => Routes.page_url(Endpoint, :comment, uuid),
|
||||
"uuid" => uuid,
|
||||
"tag" => tags |> Enum.map(fn {_, tag} -> tag end) |> Enum.uniq()
|
||||
"tag" => tags |> Enum.uniq()
|
||||
}
|
||||
|
||||
if inReplyTo do
|
||||
|
||||
Reference in New Issue
Block a user