[Pleroma.Web.ActivityPub.Transmogrifier]: Fix actor key outside of object

The code here is copied from feature/peertube by lain.

Co-authored-by: lain <lain@soykaf.club>
This commit is contained in:
Haelwenn (lanodan) Monnier 2018-07-12 23:09:42 +02:00
parent 24b5a75d09
commit 8472fba2a7
No known key found for this signature in database
GPG key ID: D5B7A8E43C997DEE

View file

@ -13,6 +13,14 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
require Logger
def get_actor(%{"actor" => actor}) when is_binary(actor) do
actor
end
def get_actor(%{"actor" => actor}) when is_list(actor) do
Enum.at(actor, 0)
end
@doc """
Modifies an incoming AP object (mastodon format) to our internal format.
"""
@ -28,16 +36,8 @@ def fix_object(object) do
end
def fix_actor(%{"attributedTo" => actor} = object) do
# attributedTo can be a list in the case of peertube or plume
actor =
if is_list(actor) do
Enum.at(actor, 0)
else
actor
end
object
|> Map.put("actor", actor)
|> Map.put("actor", get_actor(%{"actor" => actor}))
end
def fix_in_reply_to(%{"inReplyTo" => in_reply_to_id} = object)
@ -137,12 +137,12 @@ def fix_content_map(object), do: object
# - emoji
def handle_incoming(%{"type" => "Create", "object" => %{"type" => objtype} = object} = data)
when objtype in ["Article", "Note"] do
actor = get_actor(data)
data = Map.put(data, "actor", actor)
with nil <- Activity.get_create_activity_by_object_ap_id(object["id"]),
%User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do
# prefer the activity's actor instead of attributedTo
object =
fix_object(data["object"])
|> Map.put("actor", data["actor"])
object = fix_object(data["object"])
params = %{
to: data["to"],