Some fixes to AP fetching.
This commit is contained in:
parent
0e9bd6d148
commit
b76de1ecd3
@ -20,8 +20,24 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||||||
|> Map.put("actor", object["attributedTo"])
|
|> Map.put("actor", object["attributedTo"])
|
||||||
|> fix_attachments
|
|> fix_attachments
|
||||||
|> fix_context
|
|> fix_context
|
||||||
|
|> fix_in_reply_to
|
||||||
end
|
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(object["inReplyToAtomUri"] || in_reply_to_id) do
|
||||||
|
{:ok, replied_object} ->
|
||||||
|
activity = Activity.get_create_activity_by_object_ap_id(replied_object.data["id"])
|
||||||
|
object
|
||||||
|
|> Map.put("inReplyTo", replied_object.data["id"])
|
||||||
|
|> Map.put("inReplyToAtomUri", object["inReplyToAtomUri"] || in_reply_to_id)
|
||||||
|
|> Map.put("inReplyToStatusId", activity.id)
|
||||||
|
e ->
|
||||||
|
Logger.error("Couldn't fetch #{object["inReplyTo"]} #{inspect(e)}")
|
||||||
|
object
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def fix_in_reply_to(object), do: object
|
||||||
|
|
||||||
def fix_context(object) do
|
def fix_context(object) do
|
||||||
object
|
object
|
||||||
|> Map.put("context", object["conversation"])
|
|> Map.put("context", object["conversation"])
|
||||||
@ -46,19 +62,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||||||
%User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do
|
%User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do
|
||||||
object = fix_object(data["object"])
|
object = fix_object(data["object"])
|
||||||
|
|
||||||
replied_to_id = if object["inReplyTo"] do
|
|
||||||
case ActivityPub.fetch_object_from_id(object["inReplyTo"]) do
|
|
||||||
{:ok, object} -> object.data["id"]
|
|
||||||
e ->
|
|
||||||
Logger.error("Couldn't fetch #{object["inReplyTo"]} #{inspect(e)}")
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
else
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
|
|
||||||
object = Map.put(object, "inReplyTo", replied_to_id || object["inReplyTo"])
|
|
||||||
|
|
||||||
params = %{
|
params = %{
|
||||||
to: data["to"],
|
to: data["to"],
|
||||||
object: object,
|
object: object,
|
||||||
@ -139,7 +142,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||||||
def prepare_outgoing(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do
|
def prepare_outgoing(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do
|
||||||
object = object
|
object = object
|
||||||
|> prepare_object
|
|> prepare_object
|
||||||
|
|
||||||
data = data
|
data = data
|
||||||
|> Map.put("object", object)
|
|> Map.put("object", object)
|
||||||
|> Map.put("@context", "https://www.w3.org/ns/activitystreams")
|
|> Map.put("@context", "https://www.w3.org/ns/activitystreams")
|
||||||
|
@ -36,7 +36,27 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||||||
|
|
||||||
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
|
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
|
||||||
|
|
||||||
assert Activity.get_create_activity_by_object_ap_id("tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment")
|
assert activity = Activity.get_create_activity_by_object_ap_id("tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment")
|
||||||
|
assert returned_activity.data["object"]["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
|
||||||
|
assert returned_activity.data["object"]["inReplyToStatusId"] == activity.id
|
||||||
|
end
|
||||||
|
|
||||||
|
test "it works if the activity id isn't an url but an atom-uri is given" do
|
||||||
|
data = File.read!("test/fixtures/mastodon-post-activity.json")
|
||||||
|
|> Poison.decode!
|
||||||
|
|
||||||
|
object = data["object"]
|
||||||
|
|> Map.put("inReplyToAtomUri", "https://shitposter.club/notice/2827873")
|
||||||
|
|> Map.put("inReplyTo", "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment")
|
||||||
|
|
||||||
|
data = data
|
||||||
|
|> Map.put("object", object)
|
||||||
|
|
||||||
|
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
|
||||||
|
|
||||||
|
assert activity = Activity.get_create_activity_by_object_ap_id("tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment")
|
||||||
|
assert returned_activity.data["object"]["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
|
||||||
|
assert returned_activity.data["object"]["inReplyToStatusId"] == activity.id
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it works for incoming notices" do
|
test "it works for incoming notices" do
|
||||||
|
Loading…
Reference in New Issue
Block a user