Commit aa79d64e authored by lain's avatar lain

Correctly stitch mastodon -> ostatus replies.

parent 2583a9f6
Pipeline #802 failed with stage
in 3 minutes and 3 seconds
......@@ -10,6 +10,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
import Ecto.Query
require Logger
@doc """
Modifies an incoming AP object (mastodon format) to our internal format.
"""
......@@ -43,6 +45,20 @@ def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Note"} = obje
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"])
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 = %{
to: data["to"],
object: object,
......@@ -56,9 +72,6 @@ def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Note"} = obje
])
}
if object["inReplyTo"] do
{:ok, object} = ActivityPub.fetch_object_from_id(object["inReplyTo"])
end
ActivityPub.create(params)
else
......
<?xml version="1.0" encoding="UTF-8"?>
<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:georss="http://www.georss.org/georss" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:media="http://purl.org/syndication/atommedia" xmlns:statusnet="http://status.net/schema/api/1/">
<activity:object-type>http://activitystrea.ms/schema/1.0/comment</activity:object-type>
<id>tag:shitposter.club,2018-02-22:noticeId=7369654:objectType=comment</id>
<title>New comment by shpuld</title>
<content type="html">@&lt;a href=&quot;https://testing.pleroma.lol/users/lain&quot; class=&quot;h-card mention&quot; title=&quot;Rael Electric Razor&quot;&gt;lain&lt;/a&gt; me far right</content>
<link rel="alternate" type="text/html" href="https://shitposter.club/notice/7369654"/>
<status_net notice_id="7369654"></status_net>
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
<published>2018-02-22T09:20:12+00:00</published>
<updated>2018-02-22T09:20:12+00:00</updated>
<author>
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
<uri>https://shitposter.club/user/5381</uri>
<name>shpuld</name>
<link rel="alternate" type="text/html" href="https://shitposter.club/shpuld"/>
<link rel="avatar" type="image/png" media:width="864" media:height="864" href="https://shitposter.club/avatar/5381-original-20171230093854.png"/>
<link rel="avatar" type="image/png" media:width="96" media:height="96" href="https://shitposter.club/avatar/5381-96-20171230093854.png"/>
<link rel="avatar" type="image/png" media:width="48" media:height="48" href="https://shitposter.club/avatar/5381-48-20171230093854.png"/>
<link rel="avatar" type="image/png" media:width="24" media:height="24" href="https://shitposter.club/avatar/5381-24-20171230093900.png"/>
<poco:preferredUsername>shpuld</poco:preferredUsername>
<poco:displayName>shp</poco:displayName>
<followers url="https://shitposter.club/shpuld/subscribers"></followers>
<statusnet:profile_info local_id="5381"></statusnet:profile_info>
</author>
<thr:in-reply-to ref="https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b" href="https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b"></thr:in-reply-to>
<link rel="related" href="https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b"/>
<link rel="ostatus:conversation" href="https://shitposter.club/conversation/4378601"/>
<ostatus:conversation href="https://shitposter.club/conversation/4378601" local_id="4378601" ref="tag:shitposter.club,2018-02-22:objectType=thread:nonce=e5a7c72d60a9c0e4">tag:shitposter.club,2018-02-22:objectType=thread:nonce=e5a7c72d60a9c0e4</ostatus:conversation>
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://testing.pleroma.lol/users/lain"/>
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
<source>
<id>https://shitposter.club/api/statuses/user_timeline/5381.atom</id>
<title>shp</title>
<link rel="alternate" type="text/html" href="https://shitposter.club/shpuld"/>
<link rel="self" type="application/atom+xml" href="https://shitposter.club/api/statuses/user_timeline/5381.atom"/>
<link rel="license" href="https://shitposter.club/doc/tos"/>
<icon>https://shitposter.club/avatar/5381-96-20171230093854.png</icon>
<updated>2018-02-23T13:30:15+00:00</updated>
</source>
<link rel="self" type="application/atom+xml" href="https://shitposter.club/api/statuses/show/7369654.atom"/>
<link rel="edit" type="application/atom+xml" href="https://shitposter.club/api/statuses/show/7369654.atom"/>
<statusnet:notice_info local_id="7369654" source="Pleroma FE"></statusnet:notice_info>
</entry>
This diff is collapsed.
{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","movedTo":"as:movedTo","Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji"}],"id":"https://mstdn.io/users/mayuutann","type":"Person","following":"https://mstdn.io/users/mayuutann/following","followers":"https://mstdn.io/users/mayuutann/followers","inbox":"https://mstdn.io/users/mayuutann/inbox","outbox":"https://mstdn.io/users/mayuutann/outbox","preferredUsername":"mayuutann","name":"Mayutan☕","summary":"\u003cp\u003eI enjoy programming as a hobby.\u003cbr /\u003eJava.Ruby. Practicing English . I love karaoke.\u003cbr /\u003eAichi Japan.\u003cbr /\u003eI\u0026apos;d be glad if you pointed out it when my English is unnatural.\u003c/p\u003e","url":"https://mstdn.io/@mayuutann","manuallyApprovesFollowers":false,"publicKey":{"id":"https://mstdn.io/users/mayuutann#main-key","owner":"https://mstdn.io/users/mayuutann","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvz+MncrdPxQ5R99g9m8X\nY6QO1WNOsCj0wXuDmCHJxXfJx5NFYgsYSX3y2UTzoHNcxZIwbSy24HlYR44cEygy\nimiysTk3o0pVquXhFQNDBXJkAkPfY+9O/gz1FTbwEUzFS1m9zmoQUesDjHEBXvpW\nHkNRdVThsDHotiMYjd+WYS09XjCYxhUHcwsnEFZ+55y1Uz6OveY2OZH+jTEluF+s\nLLTDopY37Ogniah0zVm7Q+/WPdbjOullpWh8s/c5fYGl5xMaS950l5r4gkPU7MVE\n4dGSd/v4pUAxlZrhbRHrKMD4c9cmxn9gJuqmW49ZmPzIeG+SaLnad6zh0BN9nveR\njQIDAQAB\n-----END PUBLIC KEY-----\n"},"endpoints":{"sharedInbox":"https://mstdn.io/inbox"},"icon":{"type":"Image","mediaType":"image/jpeg","url":"https://mstdn.io/system/accounts/avatars/000/021/478/original/40fe303d51305ba4.jpg"},"image":{"type":"Image","mediaType":"image/jpeg","url":"https://mstdn.io/system/accounts/headers/000/021/478/original/4e1e9b5e1f350abb.jpg"}}
\ No newline at end of file
{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","movedTo":"as:movedTo","Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji"}],"id":"https://mstdn.io/users/mayuutann/statuses/99568293732299394","type":"Note","summary":null,"content":"\u003cp\u003e\u003cspan class=\"h-card\"\u003e\u003ca href=\"https://shitposter.club/shpuld\" class=\"u-url mention\"\u003e@\u003cspan\u003eshpuld\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e \u003cspan class=\"h-card\"\u003e\u003ca href=\"https://testing.pleroma.lol/users/lain\" class=\"u-url mention\"\u003e@\u003cspan\u003elain\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e ポポポォォォ\u003c/p\u003e","inReplyTo":"https://shitposter.club/notice/7369654","published":"2018-02-22T09:26:31Z","url":"https://mstdn.io/@mayuutann/99568293732299394","attributedTo":"https://mstdn.io/users/mayuutann","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://mstdn.io/users/mayuutann/followers","https://testing.pleroma.lol/users/lain","https://shitposter.club/user/5381"],"sensitive":false,"atomUri":"https://mstdn.io/users/mayuutann/statuses/99568293732299394","inReplyToAtomUri":"tag:shitposter.club,2018-02-22:noticeId=7369654:objectType=comment","conversation":"tag:shitposter.club,2018-02-22:objectType=thread:nonce=e5a7c72d60a9c0e4","attachment":[],"tag":[{"type":"Mention","href":"https://testing.pleroma.lol/users/lain","name":"@lain@testing.pleroma.lol"},{"type":"Mention","href":"https://shitposter.club/user/5381","name":"@shpuld@shitposter.club"}]}
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
<Subject>https://shitposter.club/user/5381</Subject>
<Alias>acct:shpuld@shitposter.club</Alias>
<Alias>https://shitposter.club/shpuld</Alias>
<Alias>https://shitposter.club/index.php/user/5381</Alias>
<Alias>https://shitposter.club/index.php/shpuld</Alias>
<Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="https://shitposter.club/shpuld"/>
<Link rel="http://gmpg.org/xfn/11" type="text/html" href="https://shitposter.club/shpuld"/>
<Link rel="describedby" type="application/rdf+xml" href="https://shitposter.club/shpuld/foaf"/>
<Link rel="http://apinamespace.org/atom" type="application/atomsvc+xml" href="https://shitposter.club/api/statusnet/app/service/shpuld.xml"/>
<Link rel="http://apinamespace.org/twitter" href="https://shitposter.club/api/"/>
<Link rel="http://specs.openid.net/auth/2.0/provider" href="https://shitposter.club/shpuld"/>
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="https://shitposter.club/api/statuses/user_timeline/5381.atom"/>
<Link rel="magic-public-key" href="data:application/magic-public-key,RSA.pkJ_xCKxFzcOKuKPKFhUTkWLWyWAIRDS8onxRLxVvxITQAkHIO1Rl9FS_1DAT3MK_wBcbzXm1TwlVOQFY5I2zrZQGxUvGDUlqcsf9sQyQaNvVVoU83nAV2w9bQZ-GlaLCMHWKN4yBBCTPfu9J6XbItxbHhJg5ub8z5drDF45te8=.AQAB"/>
<Link rel="salmon" href="https://shitposter.club/main/salmon/user/5381"/>
<Link rel="http://salmon-protocol.org/ns/salmon-replies" href="https://shitposter.club/main/salmon/user/5381"/>
<Link rel="http://salmon-protocol.org/ns/salmon-mention" href="https://shitposter.club/main/salmon/user/5381"/>
<Link rel="http://ostatus.org/schema/1.0/subscribe" template="https://shitposter.club/main/ostatussub?profile={uri}"/>
</XRD>
......@@ -80,6 +80,13 @@ def get("https://shitposter.club/.well-known/webfinger?resource=https://shitpost
}}
end
def get("https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381", [Accept: "application/xrd+xml"], []) do
{:ok, %Response{
status_code: 200,
body: File.read!("test/fixtures/httpoison_mock/spc_5381_xrd.xml")
}}
end
def get("http://gs.example.org/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "http://gs.example.org:4040/index.php/user/1"], follow_redirect: true]) do
{:ok, %Response{
status_code: 200,
......@@ -122,6 +129,13 @@ def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _bod
}}
end
def get("https://shitposter.club/api/statuses/user_timeline/5381.atom", _body, _headers) do
{:ok, %Response{
status_code: 200,
body: File.read!("test/fixtures/httpoison_mock/spc_5381.atom")
}}
end
def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _body, _headers) do
{:ok, %Response{
status_code: 200,
......@@ -387,6 +401,13 @@ def get("https://niu.moe/users/rye", ["Accept": "application/activity+json"], _)
}}
end
def get("https://mstdn.io/users/mayuutann", ["Accept": "application/activity+json"], _) do
{:ok, %Response{
status_code: 200,
body: File.read!("test/fixtures/httpoison_mock/mayumayu.json")
}}
end
def get("http://mastodon.example.org/@admin/99541947525187367", ["Accept": "application/activity+json"], _) do
{:ok, %Response{
status_code: 200,
......@@ -394,6 +415,27 @@ def get("http://mastodon.example.org/@admin/99541947525187367", ["Accept": "appl
}}
end
def get("https://mstdn.io/users/mayuutann/statuses/99568293732299394", ["Accept": "application/activity+json"], _) do
{:ok, %Response{
status_code: 200,
body: File.read!("test/fixtures/httpoison_mock/mayumayupost.json")
}}
end
def get("https://shitposter.club/notice/7369654", _, _) do
{:ok, %Response{
status_code: 200,
body: File.read!("test/fixtures/httpoison_mock/7369654.html")
}}
end
def get("https://shitposter.club/api/statuses/show/7369654.atom", _body, _headers) do
{:ok, %Response{
status_code: 200,
body: File.read!("test/fixtures/httpoison_mock/7369654.atom")
}}
end
def get(url, body, headers) do
{:error, "Not implemented the mock response for get #{inspect(url)}, #{inspect(body)}, #{inspect(headers)}"}
end
......
......@@ -288,6 +288,14 @@ test "it works with objects only available via Ostatus" do
assert object == object_again
end
test "it correctly stitches up conversations between ostatus and ap" do
last = "https://mstdn.io/users/mayuutann/statuses/99568293732299394"
{:ok, object} = ActivityPub.fetch_object_from_id(last)
object = Object.get_by_ap_id(object.data["inReplyTo"])
assert object
end
end
describe "following / unfollowing" do
......
......@@ -10,11 +10,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
alias Pleroma.Web.CommonAPI
describe "handle_incoming" do
test "it correctly connects AP and non-AP statuses" do
last = "https://mstdn.io/users/mayuutann/statuses/99568293732299394"
end
test "it ignores an incoming notice if we already have it" do
activity = insert(:note_activity)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment