From 8472fba2a729f7764ffaf2a4744533c8a95adadb Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 12 Jul 2018 23:09:42 +0200 Subject: [PATCH] [Pleroma.Web.ActivityPub.Transmogrifier]: Fix actor key outside of object The code here is copied from feature/peertube by lain. Co-authored-by: lain --- .../web/activity_pub/transmogrifier.ex | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 0d2166196..6080303b6 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -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"],