Handle mastodon conversation ids.
authorRoger Braun <roger@rogerbraun.net>
Mon, 4 Sep 2017 09:03:51 +0000 (11:03 +0200)
committerRoger Braun <roger@rogerbraun.net>
Mon, 4 Sep 2017 09:03:51 +0000 (11:03 +0200)
lib/pleroma/web/ostatus/handlers/note_handler.ex
test/fixtures/mastodon_conversation.xml [new file with mode: 0644]
test/web/ostatus/ostatus_test.exs

index f9aa463a0432300700eb1ee5462487241a998aee..54c9e85d553dd12c3fb6fac6c6c0e985ebfbf0ed 100644 (file)
@@ -24,7 +24,10 @@ defmodule Pleroma.Web.OStatus.NoteHandler do
   3. A newly generated context id.
   """
   def get_context(entry, inReplyTo) do
-    context = (XML.string_from_xpath("//ostatus:conversation[1]", entry) || "") |> String.trim
+    context = (
+      XML.string_from_xpath("//ostatus:conversation[1]", entry)
+      || XML.string_from_xpath("//ostatus:conversation[1]/@ref", entry)
+      || "") |> String.trim
 
     with %{data: %{"context" => context}} <- Object.get_cached_by_ap_id(inReplyTo) do
       context
diff --git a/test/fixtures/mastodon_conversation.xml b/test/fixtures/mastodon_conversation.xml
new file mode 100644 (file)
index 0000000..8faab23
--- /dev/null
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<entry xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:media="http://purl.org/syndication/atommedia" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:mastodon="http://mastodon.social/schema/1.0">
+  <id>tag:mastodon.social,2017-08-28:objectId=16402826:objectType=Status</id>
+  <published>2017-08-28T17:58:55Z</published>
+  <updated>2017-08-28T17:58:55Z</updated>
+  <title>New status by lambadalambda</title>
+  <author>
+    <id>https://mastodon.social/users/lambadalambda</id>
+    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
+    <uri>https://mastodon.social/users/lambadalambda</uri>
+    <name>lambadalambda</name>
+    <email>lambadalambda@mastodon.social</email>
+    <link rel="alternate" type="text/html" href="https://mastodon.social/@lambadalambda"/>
+    <link rel="avatar" type="image/gif" media:width="120" media:height="120" href="https://files.mastodon.social/accounts/avatars/000/000/264/original/1429214160519.gif"/>
+    <link rel="header" type="image/gif" media:width="700" media:height="335" href="https://files.mastodon.social/accounts/headers/000/000/264/original/28b26104f83747d2.gif"/>
+    <poco:preferredUsername>lambadalambda</poco:preferredUsername>
+    <poco:displayName>Critical Value</poco:displayName>
+    <mastodon:scope>public</mastodon:scope>
+  </author>
+  <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
+  <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
+  <link rel="alternate" type="application/activity+json" href="https://mastodon.social/users/lambadalambda/statuses/16402826"/>
+  <content type="html" xml:lang="">&lt;p&gt;test. &lt;a href="https://mastodon.social/media/XCp0OHGPON9kWZwhjaI" rel="nofollow noopener" target="_blank"&gt;&lt;span class="invisible"&gt;https://&lt;/span&gt;&lt;span class="ellipsis"&gt;mastodon.social/media/XCp0OHGP&lt;/span&gt;&lt;span class="invisible"&gt;ON9kWZwhjaI&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;</content>
+  <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
+  <link rel="enclosure" type="image/png" length="307682" href="https://files.mastodon.social/media_attachments/files/001/271/957/original/6b426b164a09a40e.png"/>
+  <mastodon:scope>public</mastodon:scope>
+  <link rel="alternate" type="text/html" href="https://mastodon.social/users/lambadalambda/updates/4215320"/>
+  <link rel="self" type="application/atom+xml" href="https://mastodon.social/users/lambadalambda/updates/4215320.atom"/>
+  <ostatus:conversation ref="tag:mastodon.social,2017-08-28:objectId=7876885:objectType=Conversation"/>
+</entry>
index 8dd3c3b54c65d77a8cf50a772ad92c1636191246..ee2b79ffa6d8566783689fbf49255a7007fe4f81 100644 (file)
@@ -182,6 +182,13 @@ defmodule Pleroma.Web.OStatusTest do
     refute favorited_activity.local
   end
 
+  test "handle conversation references" do
+    incoming = File.read!("test/fixtures/mastodon_conversation.xml")
+    {:ok, [activity]} = OStatus.handle_incoming(incoming)
+
+    assert activity.data["context"] == "tag:mastodon.social,2017-08-28:objectId=7876885:objectType=Conversation"
+  end
+
   test "handle incoming favorites with locally available object - GS, websub" do
     note_activity = insert(:note_activity)