forked from mirrors/akkoma
Merge branch 'fix/ostatus-activity-representer-depends-on-emebeded-objects' into 'develop'
Fix get_in_reply_to in OStatus' activity representer depending on embedded objects See merge request pleroma/pleroma!1129
This commit is contained in:
commit
131f883207
2 changed files with 23 additions and 28 deletions
|
@ -18,14 +18,17 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_in_reply_to(%{"object" => %{"inReplyTo" => in_reply_to}}) do
|
defp get_in_reply_to(activity) do
|
||||||
|
with %Object{data: %{"inReplyTo" => in_reply_to}} <- Object.normalize(activity) do
|
||||||
[
|
[
|
||||||
{:"thr:in-reply-to",
|
{:"thr:in-reply-to",
|
||||||
[ref: to_charlist(in_reply_to), href: to_charlist(get_href(in_reply_to))], []}
|
[ref: to_charlist(in_reply_to), href: to_charlist(get_href(in_reply_to))], []}
|
||||||
]
|
]
|
||||||
|
else
|
||||||
|
_ ->
|
||||||
|
[]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_in_reply_to(_), do: []
|
|
||||||
|
|
||||||
defp get_mentions(to) do
|
defp get_mentions(to) do
|
||||||
Enum.map(to, fn id ->
|
Enum.map(to, fn id ->
|
||||||
|
@ -98,7 +101,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
|
||||||
[]}
|
[]}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
in_reply_to = get_in_reply_to(activity.data)
|
in_reply_to = get_in_reply_to(activity)
|
||||||
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
|
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
|
||||||
mentions = activity.recipients |> get_mentions
|
mentions = activity.recipients |> get_mentions
|
||||||
|
|
||||||
|
@ -146,7 +149,6 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
|
||||||
updated_at = activity.data["published"]
|
updated_at = activity.data["published"]
|
||||||
inserted_at = activity.data["published"]
|
inserted_at = activity.data["published"]
|
||||||
|
|
||||||
_in_reply_to = get_in_reply_to(activity.data)
|
|
||||||
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
|
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
|
||||||
mentions = activity.recipients |> get_mentions
|
mentions = activity.recipients |> get_mentions
|
||||||
|
|
||||||
|
@ -177,7 +179,6 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
|
||||||
updated_at = activity.data["published"]
|
updated_at = activity.data["published"]
|
||||||
inserted_at = activity.data["published"]
|
inserted_at = activity.data["published"]
|
||||||
|
|
||||||
_in_reply_to = get_in_reply_to(activity.data)
|
|
||||||
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
|
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
|
||||||
|
|
||||||
retweeted_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
|
retweeted_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
|
||||||
|
|
|
@ -67,37 +67,31 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "a reply note" do
|
test "a reply note" do
|
||||||
note = insert(:note_activity)
|
user = insert(:user)
|
||||||
answer = insert(:note_activity)
|
note_object = insert(:note)
|
||||||
object = answer.data["object"]
|
_note = insert(:note_activity, %{note: note_object})
|
||||||
object = Map.put(object, "inReplyTo", note.data["object"]["id"])
|
object = insert(:note, %{data: %{"inReplyTo" => note_object.data["id"]}})
|
||||||
|
answer = insert(:note_activity, %{note: object})
|
||||||
data = %{answer.data | "object" => object}
|
|
||||||
answer = %{answer | data: data}
|
|
||||||
|
|
||||||
note_object = Object.get_by_ap_id(note.data["object"]["id"])
|
|
||||||
|
|
||||||
Repo.update!(
|
Repo.update!(
|
||||||
Object.change(note_object, %{data: Map.put(note_object.data, "external_url", "someurl")})
|
Object.change(note_object, %{data: Map.put(note_object.data, "external_url", "someurl")})
|
||||||
)
|
)
|
||||||
|
|
||||||
user = User.get_cached_by_ap_id(answer.data["actor"])
|
|
||||||
|
|
||||||
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["object"]["id"]}</id>
|
<id>#{object.data["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">#{object.data["content"]}</content>
|
||||||
<published>#{answer.data["object"]["published"]}</published>
|
<published>#{object.data["published"]}</published>
|
||||||
<updated>#{answer.data["object"]["published"]}</updated>
|
<updated>#{object.data["published"]}</updated>
|
||||||
<ostatus:conversation ref="#{answer.data["context"]}">#{answer.data["context"]}</ostatus:conversation>
|
<ostatus:conversation ref="#{answer.data["context"]}">#{answer.data["context"]}</ostatus:conversation>
|
||||||
<link ref="#{answer.data["context"]}" rel="ostatus:conversation" />
|
<link ref="#{answer.data["context"]}" rel="ostatus:conversation" />
|
||||||
<summary>2hu</summary>
|
<summary>2hu</summary>
|
||||||
<link type="application/atom+xml" href="#{answer.data["object"]["id"]}" rel="self" />
|
<link type="application/atom+xml" href="#{object.data["id"]}" rel="self" />
|
||||||
<link type="text/html" href="#{answer.data["object"]["id"]}" rel="alternate" />
|
<link type="text/html" href="#{object.data["id"]}" rel="alternate" />
|
||||||
<category term="2hu"/>
|
<category term="2hu"/>
|
||||||
<thr:in-reply-to ref="#{note.data["object"]["id"]}" href="someurl" />
|
<thr:in-reply-to ref="#{note_object.data["id"]}" href="someurl" />
|
||||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
|
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
|
||||||
<link name="2hu" rel="emoji" href="corndog.png" />
|
<link name="2hu" rel="emoji" href="corndog.png" />
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue