Federate object id for posts in ostatus.

This is because ostatus doens't have an id for the activities.
This commit is contained in:
Roger Braun 2017-04-30 11:55:19 +02:00
parent 84027ff00b
commit 62607f37dc
4 changed files with 8 additions and 13 deletions

View file

@ -3,13 +3,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
require Logger require Logger
defp get_in_reply_to(%{"object" => %{ "inReplyTo" => in_reply_to}}) do defp get_in_reply_to(%{"object" => %{ "inReplyTo" => in_reply_to}}) do
with %Activity{data: %{"id" => id}} <- Activity.get_create_activity_by_object_ap_id(in_reply_to) do [{:"thr:in-reply-to", [ref: to_charlist(in_reply_to)], []}]
[{:"thr:in-reply-to", [ref: to_charlist(id)], []}]
else _e ->
Logger.debug("Couldn't find replied-to activity:")
Logger.debug(in_reply_to)
[]
end
end end
defp get_in_reply_to(_), do: [] defp get_in_reply_to(_), do: []
@ -32,7 +26,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
[ [
{:"activity:object-type", ['http://activitystrea.ms/schema/1.0/note']}, {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/note']},
{:"activity:verb", ['http://activitystrea.ms/schema/1.0/post']}, {:"activity:verb", ['http://activitystrea.ms/schema/1.0/post']},
{:id, h.(activity.data["id"])}, {:id, h.(activity.data["object"]["id"])}, # For notes, federate the object id.
{:title, ['New note by #{user.nickname}']}, {:title, ['New note by #{user.nickname}']},
{:content, [type: 'html'], h.(activity.data["object"]["content"])}, {:content, [type: 'html'], h.(activity.data["object"]["content"])},
{:published, h.(inserted_at)}, {:published, h.(inserted_at)},

View file

@ -69,6 +69,7 @@ defmodule Pleroma.Web.OStatus do
id = string_from_xpath("/entry/id", entry) id = string_from_xpath("/entry/id", entry)
object = %{ object = %{
"id" => id,
"type" => "Note", "type" => "Note",
"to" => to, "to" => to,
"content" => content_html, "content" => content_html,
@ -85,7 +86,7 @@ defmodule Pleroma.Web.OStatus do
object object
end end
ActivityPub.create(to, actor, context, object, %{"id" => id}, date) ActivityPub.create(to, actor, context, object, %{}, date)
end end
def find_or_make_user(uri) do def find_or_make_user(uri) do

View file

@ -18,7 +18,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
expected = """ expected = """
<activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type> <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb> <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
<id>#{note_activity.data["id"]}</id> <id>#{note_activity.data["object"]["id"]}</id>
<title>New note by #{user.nickname}</title> <title>New note by #{user.nickname}</title>
<content type="html">#{note_activity.data["object"]["content"]}</content> <content type="html">#{note_activity.data["object"]["content"]}</content>
<published>#{inserted_at}</published> <published>#{inserted_at}</published>
@ -53,14 +53,14 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
expected = """ expected = """
<activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type> <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb> <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
<id>#{answer.data["id"]}</id> <id>#{answer.data["object"]["id"]}</id>
<title>New note by #{user.nickname}</title> <title>New note by #{user.nickname}</title>
<content type="html">#{answer.data["object"]["content"]}</content> <content type="html">#{answer.data["object"]["content"]}</content>
<published>#{inserted_at}</published> <published>#{inserted_at}</published>
<updated>#{updated_at}</updated> <updated>#{updated_at}</updated>
<ostatus:conversation>#{answer.data["context"]}</ostatus:conversation> <ostatus:conversation>#{answer.data["context"]}</ostatus:conversation>
<link href="#{answer.data["context"]}" rel="ostatus:conversation" /> <link href="#{answer.data["context"]}" rel="ostatus:conversation" />
<thr:in-reply-to ref="#{note.data["id"]}" /> <thr:in-reply-to ref="#{note.data["object"]["id"]}" />
""" """
tuple = ActivityRepresenter.to_simple_form(answer, user) tuple = ActivityRepresenter.to_simple_form(answer, user)

View file

@ -7,8 +7,8 @@ defmodule Pleroma.Web.OStatusTest do
{:ok, [activity]} = OStatus.handle_incoming(incoming) {:ok, [activity]} = OStatus.handle_incoming(incoming)
assert activity.data["type"] == "Create" assert activity.data["type"] == "Create"
assert activity.data["id"] == "tag:gs.example.org:4040,2017-04-23:noticeId=29:objectType=note"
assert activity.data["object"]["type"] == "Note" assert activity.data["object"]["type"] == "Note"
assert activity.data["object"]["id"] == "tag:gs.example.org:4040,2017-04-23:noticeId=29:objectType=note"
assert activity.data["published"] == "2017-04-23T14:51:03+00:00" assert activity.data["published"] == "2017-04-23T14:51:03+00:00"
assert activity.data["context"] == "tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b" assert activity.data["context"] == "tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b"
assert "http://pleroma.example.org:4000/users/lain3" in activity.data["to"] assert "http://pleroma.example.org:4000/users/lain3" in activity.data["to"]