mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-18 02:49:18 +00:00
Merge branch 'bugfix/activitypub-object-actor' into 'develop'
activitypub: more robustly handle object-to-actor associations See merge request pleroma/pleroma!250
This commit is contained in:
commit
b1fcfcfae1
|
@ -18,7 +18,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||
"""
|
||||
def fix_object(object) do
|
||||
object
|
||||
|> Map.put("actor", object["attributedTo"])
|
||||
|> fix_actor
|
||||
|> fix_attachments
|
||||
|> fix_context
|
||||
|> fix_in_reply_to
|
||||
|
@ -27,6 +27,19 @@ def fix_object(object) do
|
|||
|> fix_content_map
|
||||
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)
|
||||
end
|
||||
|
||||
def fix_in_reply_to(%{"inReplyTo" => in_reply_to_id} = object)
|
||||
when not is_nil(in_reply_to_id) do
|
||||
case ActivityPub.fetch_object_from_id(in_reply_to_id) do
|
||||
|
@ -126,7 +139,10 @@ def handle_incoming(%{"type" => "Create", "object" => %{"type" => objtype} = obj
|
|||
when objtype in ["Article", "Note"] do
|
||||
with nil <- Activity.get_create_activity_by_object_ap_id(object["id"]),
|
||||
%User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do
|
||||
object = fix_object(data["object"])
|
||||
# prefer the activity's actor instead of attributedTo
|
||||
object =
|
||||
fix_object(data["object"])
|
||||
|> Map.put("actor", data["actor"])
|
||||
|
||||
params = %{
|
||||
to: data["to"],
|
||||
|
|
Loading…
Reference in a new issue