[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:
parent
24b5a75d09
commit
8472fba2a7
|
@ -13,6 +13,14 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
||||||
|
|
||||||
require Logger
|
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 """
|
@doc """
|
||||||
Modifies an incoming AP object (mastodon format) to our internal format.
|
Modifies an incoming AP object (mastodon format) to our internal format.
|
||||||
"""
|
"""
|
||||||
|
@ -28,16 +36,8 @@ def fix_object(object) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def fix_actor(%{"attributedTo" => actor} = object) do
|
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
|
object
|
||||||
|> Map.put("actor", actor)
|
|> Map.put("actor", get_actor(%{"actor" => actor}))
|
||||||
end
|
end
|
||||||
|
|
||||||
def fix_in_reply_to(%{"inReplyTo" => in_reply_to_id} = object)
|
def fix_in_reply_to(%{"inReplyTo" => in_reply_to_id} = object)
|
||||||
|
@ -137,12 +137,12 @@ def fix_content_map(object), do: object
|
||||||
# - emoji
|
# - emoji
|
||||||
def handle_incoming(%{"type" => "Create", "object" => %{"type" => objtype} = object} = data)
|
def handle_incoming(%{"type" => "Create", "object" => %{"type" => objtype} = object} = data)
|
||||||
when objtype in ["Article", "Note"] do
|
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"]),
|
with nil <- Activity.get_create_activity_by_object_ap_id(object["id"]),
|
||||||
%User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do
|
%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"])
|
||||||
object =
|
|
||||||
fix_object(data["object"])
|
|
||||||
|> Map.put("actor", data["actor"])
|
|
||||||
|
|
||||||
params = %{
|
params = %{
|
||||||
to: data["to"],
|
to: data["to"],
|
||||||
|
|
Loading…
Reference in New Issue