From f1ebf812eede5b77931d2315757a7ad8e0ea5a7e Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 26 Apr 2017 10:22:51 +0200 Subject: [PATCH] Add inReplyTo to incoming messages. --- lib/pleroma/web/ostatus/ostatus.ex | 8 ++++ .../incoming_note_activity_answer.xml | 42 +++++++++++++++++++ test/web/ostatus/ostatus_test.exs | 10 +++++ 3 files changed, 60 insertions(+) create mode 100644 test/fixtures/incoming_note_activity_answer.xml diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 65141f826..5b68f057e 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -65,6 +65,14 @@ def handle_note(doc) do "actor" => actor.ap_id } + inReplyTo = string_from_xpath("/entry/thr:in-reply-to[1]/@href", doc) + + object = if inReplyTo do + Map.put(object, "inReplyTo", inReplyTo) + else + object + end + ActivityPub.create(to, actor, context, object, %{}, date) end diff --git a/test/fixtures/incoming_note_activity_answer.xml b/test/fixtures/incoming_note_activity_answer.xml new file mode 100644 index 000000000..b1244faa6 --- /dev/null +++ b/test/fixtures/incoming_note_activity_answer.xml @@ -0,0 +1,42 @@ + + http://activitystrea.ms/schema/1.0/note + tag:gs.example.org:4040,2017-04-25:noticeId=55:objectType=note + New note by lambda + hey. + + + http://activitystrea.ms/schema/1.0/post + 2017-04-25T18:16:13+00:00 + 2017-04-25T18:16:13+00:00 + + http://activitystrea.ms/schema/1.0/person + http://gs.example.org:4040/index.php/user/1 + lambda + + + + + lambda + lambda + + + + + + + http://pleroma.example.org:4000/contexts/8f6f45d4-8e4d-4e1a-a2de-09f27367d2d0 + + + + http://gs.example.org:4040/index.php/api/statuses/user_timeline/1.atom + lambda + + + + http://gs.example.org:4040/theme/neo-gnu/default-avatar-profile.png + 2017-04-25T18:16:13+00:00 + + + + + diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index dffebf5a7..96f2cb4f3 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -13,6 +13,16 @@ test "handle incoming notes" do assert "http://pleroma.example.org:4000/users/lain3" in activity.data["to"] end + test "handle incoming replies" do + incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml") + {:ok, activity} = OStatus.handle_incoming(incoming) + + assert activity.data["type"] == "Create" + assert activity.data["object"]["type"] == "Note" + assert activity.data["object"]["inReplyTo"] == "http://pleroma.example.org:4000/objects/55bce8fc-b423-46b1-af71-3759ab4670bc" + assert "http://pleroma.example.org:4000/users/lain5" in activity.data["to"] + end + describe "new remote user creation" do test "make new user or find them based on an 'author' xml doc" do incoming = File.read!("test/fixtures/user_name_only.xml")