A module to handle coding from internal to wire ActivityPub and back.
"""
alias Pleroma.Activity
+ alias Pleroma.EarmarkRenderer
alias Pleroma.FollowingRelationship
alias Pleroma.Object
alias Pleroma.Object.Containment
|> fix_addressing
|> fix_summary
|> fix_type(options)
+ |> fix_content
end
def fix_summary(%{"summary" => nil} = object) do
def fix_type(object, _), do: object
+ defp fix_content(%{"mediaType" => "text/markdown", "content" => content} = object)
+ when is_binary(content) do
+ html_content =
+ content
+ |> Earmark.as_html!(%Earmark.Options{renderer: EarmarkRenderer})
+ |> Pleroma.HTML.filter_tags()
+
+ Map.merge(object, %{"content" => html_content, "mediaType" => "text/html"})
+ end
+
+ defp fix_content(object), do: object
+
defp mastodon_follow_hack(%{"id" => id, "actor" => follower_id}, followed) do
with true <- id =~ "follows",
%User{local: true} = follower <- User.get_cached_by_ap_id(follower_id),
def prepare_attachments(object) do
attachments =
- (object["attachment"] || [])
+ object
+ |> Map.get("attachment", [])
|> Enum.map(fn data ->
[%{"mediaType" => media_type, "href" => href} | _] = data["url"]
- %{"url" => href, "mediaType" => media_type, "name" => data["name"], "type" => "Document"}
+
+ %{
+ "url" => href,
+ "mediaType" => media_type,
+ "name" => data["name"],
+ "type" => "Document"
+ }
end)
Map.put(object, "attachment", attachments)
end
def strip_internal_fields(object) do
- object
- |> Map.drop(Pleroma.Constants.object_internal_fields())
+ Map.drop(object, Pleroma.Constants.object_internal_fields())
end
defp strip_internal_tags(%{"tag" => tags} = object) do