1
0
Fork 0
forked from mirrors/akkoma

Handle mastodon conversation ids.

This commit is contained in:
Roger Braun 2017-09-04 11:03:51 +02:00
parent 485cc0bc6a
commit 1b1f861bad
3 changed files with 41 additions and 1 deletions

View file

@ -24,7 +24,10 @@ def fetch_replied_to_activity(entry, inReplyTo) do
3. A newly generated context id. 3. A newly generated context id.
""" """
def get_context(entry, inReplyTo) do 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 with %{data: %{"context" => context}} <- Object.get_cached_by_ap_id(inReplyTo) do
context context

30
test/fixtures/mastodon_conversation.xml vendored Normal file
View file

@ -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>

View file

@ -182,6 +182,13 @@ test "handle incoming favorites - GS, websub" do
refute favorited_activity.local refute favorited_activity.local
end 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 test "handle incoming favorites with locally available object - GS, websub" do
note_activity = insert(:note_activity) note_activity = insert(:note_activity)