forked from YokaiRick/akkoma
Merge branch 'accept-embedded-announce-object' into 'develop'
Import object from self-Announce whenever possible See merge request pleroma/pleroma!1770
This commit is contained in:
commit
45b7f03f89
5 changed files with 145 additions and 1 deletions
|
@ -580,7 +580,7 @@ def handle_incoming(
|
||||||
) do
|
) do
|
||||||
with actor <- Containment.get_actor(data),
|
with actor <- Containment.get_actor(data),
|
||||||
{:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
|
{:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
|
||||||
{:ok, object} <- get_obj_helper(object_id),
|
{:ok, object} <- get_embedded_obj_helper(object_id, actor),
|
||||||
public <- Visibility.is_public?(data),
|
public <- Visibility.is_public?(data),
|
||||||
{:ok, activity, _object} <- ActivityPub.announce(actor, object, id, false, public) do
|
{:ok, activity, _object} <- ActivityPub.announce(actor, object, id, false, public) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
|
@ -782,6 +782,29 @@ def get_obj_helper(id, options \\ []) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec get_embedded_obj_helper(String.t() | Object.t(), User.t()) :: {:ok, Object.t()} | nil
|
||||||
|
def get_embedded_obj_helper(%{"attributedTo" => attributed_to, "id" => object_id} = data, %User{
|
||||||
|
ap_id: ap_id
|
||||||
|
})
|
||||||
|
when attributed_to == ap_id do
|
||||||
|
with {:ok, activity} <-
|
||||||
|
handle_incoming(%{
|
||||||
|
"type" => "Create",
|
||||||
|
"to" => data["to"],
|
||||||
|
"cc" => data["cc"],
|
||||||
|
"actor" => attributed_to,
|
||||||
|
"object" => data
|
||||||
|
}) do
|
||||||
|
{:ok, Object.normalize(activity)}
|
||||||
|
else
|
||||||
|
_ -> get_obj_helper(object_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_embedded_obj_helper(object_id, _) do
|
||||||
|
get_obj_helper(object_id)
|
||||||
|
end
|
||||||
|
|
||||||
def set_reply_to_uri(%{"inReplyTo" => in_reply_to} = object) when is_binary(in_reply_to) do
|
def set_reply_to_uri(%{"inReplyTo" => in_reply_to} = object) when is_binary(in_reply_to) do
|
||||||
with false <- String.starts_with?(in_reply_to, "http"),
|
with false <- String.starts_with?(in_reply_to, "http"),
|
||||||
{:ok, %{data: replied_to_object}} <- get_obj_helper(in_reply_to) do
|
{:ok, %{data: replied_to_object}} <- get_obj_helper(in_reply_to) do
|
||||||
|
|
43
test/fixtures/bogus-mastodon-announce.json
vendored
Normal file
43
test/fixtures/bogus-mastodon-announce.json
vendored
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
{
|
||||||
|
"type": "Announce",
|
||||||
|
"to": [
|
||||||
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
|
],
|
||||||
|
"published": "2018-02-17T19:39:15Z",
|
||||||
|
"object": {
|
||||||
|
"type": "Note",
|
||||||
|
"id": "https://mastodon.social/users/emelie/statuses/101849165031453404",
|
||||||
|
"attributedTo": "https://mastodon.social/users/emelie",
|
||||||
|
"content": "this is a public toot",
|
||||||
|
"to": [
|
||||||
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
|
],
|
||||||
|
"cc": [
|
||||||
|
"https://mastodon.social/users/emelie",
|
||||||
|
"https://mastodon.social/users/emelie/followers"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"id": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
|
||||||
|
"cc": [
|
||||||
|
"http://mastodon.example.org/users/admin",
|
||||||
|
"http://mastodon.example.org/users/admin/followers"
|
||||||
|
],
|
||||||
|
"atomUri": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
|
||||||
|
"actor": "http://mastodon.example.org/users/admin",
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://w3id.org/security/v1",
|
||||||
|
{
|
||||||
|
"toot": "http://joinmastodon.org/ns#",
|
||||||
|
"sensitive": "as:sensitive",
|
||||||
|
"ostatus": "http://ostatus.org#",
|
||||||
|
"movedTo": "as:movedTo",
|
||||||
|
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||||
|
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||||
|
"conversation": "ostatus:conversation",
|
||||||
|
"atomUri": "ostatus:atomUri",
|
||||||
|
"Hashtag": "as:Hashtag",
|
||||||
|
"Emoji": "toot:Emoji"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
35
test/fixtures/mastodon-announce-private.json
vendored
Normal file
35
test/fixtures/mastodon-announce-private.json
vendored
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"type": "Announce",
|
||||||
|
"to": [
|
||||||
|
"http://mastodon.example.org/users/admin/followers"
|
||||||
|
],
|
||||||
|
"published": "2018-02-17T19:39:15Z",
|
||||||
|
"object": {
|
||||||
|
"type": "Note",
|
||||||
|
"id": "http://mastodon.example.org/@admin/99541947525187368",
|
||||||
|
"attributedTo": "http://mastodon.example.org/users/admin",
|
||||||
|
"content": "this is a private toot",
|
||||||
|
"to": [
|
||||||
|
"http://mastodon.example.org/users/admin/followers"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"id": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
|
||||||
|
"atomUri": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
|
||||||
|
"actor": "http://mastodon.example.org/users/admin",
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://w3id.org/security/v1",
|
||||||
|
{
|
||||||
|
"toot": "http://joinmastodon.org/ns#",
|
||||||
|
"sensitive": "as:sensitive",
|
||||||
|
"ostatus": "http://ostatus.org#",
|
||||||
|
"movedTo": "as:movedTo",
|
||||||
|
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||||
|
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||||
|
"conversation": "ostatus:conversation",
|
||||||
|
"atomUri": "ostatus:atomUri",
|
||||||
|
"Hashtag": "as:Hashtag",
|
||||||
|
"Emoji": "toot:Emoji"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -46,6 +46,14 @@ def get("https://mastodon.social/users/emelie/statuses/101849165031453009", _, _
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get("https://mastodon.social/users/emelie/statuses/101849165031453404", _, _, _) do
|
||||||
|
{:ok,
|
||||||
|
%Tesla.Env{
|
||||||
|
status: 404,
|
||||||
|
body: ""
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
|
||||||
def get("https://mastodon.social/users/emelie", _, _, _) do
|
def get("https://mastodon.social/users/emelie", _, _, _) do
|
||||||
{:ok,
|
{:ok,
|
||||||
%Tesla.Env{
|
%Tesla.Env{
|
||||||
|
@ -349,6 +357,14 @@ def get(
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get("http://mastodon.example.org/@admin/99541947525187368", _, _, _) do
|
||||||
|
{:ok,
|
||||||
|
%Tesla.Env{
|
||||||
|
status: 404,
|
||||||
|
body: ""
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
|
||||||
def get("https://shitposter.club/notice/7369654", _, _, _) do
|
def get("https://shitposter.club/notice/7369654", _, _, _) do
|
||||||
{:ok,
|
{:ok,
|
||||||
%Tesla.Env{
|
%Tesla.Env{
|
||||||
|
|
|
@ -442,6 +442,33 @@ test "it works for incoming announces with an existing activity" do
|
||||||
assert Activity.get_create_by_object_ap_id(data["object"]).id == activity.id
|
assert Activity.get_create_by_object_ap_id(data["object"]).id == activity.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it works for incoming announces with an inlined activity" do
|
||||||
|
data =
|
||||||
|
File.read!("test/fixtures/mastodon-announce-private.json")
|
||||||
|
|> Poison.decode!()
|
||||||
|
|
||||||
|
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||||
|
|
||||||
|
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||||
|
assert data["type"] == "Announce"
|
||||||
|
|
||||||
|
assert data["id"] ==
|
||||||
|
"http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
|
||||||
|
|
||||||
|
object = Object.normalize(data["object"])
|
||||||
|
|
||||||
|
assert object.data["id"] == "http://mastodon.example.org/@admin/99541947525187368"
|
||||||
|
assert object.data["content"] == "this is a private toot"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "it rejects incoming announces with an inlined activity from another origin" do
|
||||||
|
data =
|
||||||
|
File.read!("test/fixtures/bogus-mastodon-announce.json")
|
||||||
|
|> Poison.decode!()
|
||||||
|
|
||||||
|
assert :error = Transmogrifier.handle_incoming(data)
|
||||||
|
end
|
||||||
|
|
||||||
test "it does not clobber the addressing on announce activities" do
|
test "it does not clobber the addressing on announce activities" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
|
||||||
|
|
Loading…
Reference in a new issue