From e4523c301023de0d4cff5ca0168094fea25955a2 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 9 May 2019 22:27:00 +0300 Subject: [PATCH 1/2] Fix get_in_reply_to in OStatus' activity representer depending on embedded objects --- .../web/ostatus/activity_representer.ex | 19 +++++++----- .../web/ostatus/activity_representer_test.exs | 30 ++++++++----------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index 166691a09..a7832a3d9 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -18,15 +18,18 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do end end - defp get_in_reply_to(%{"object" => %{"inReplyTo" => in_reply_to}}) do - [ - {:"thr:in-reply-to", - [ref: to_charlist(in_reply_to), href: to_charlist(get_href(in_reply_to))], []} - ] + defp get_in_reply_to(activity) do + with %Object{data: %{"inReplyTo" => in_reply_to}} <- Object.normalize(activity) do + [ + {:"thr:in-reply-to", + [ref: to_charlist(in_reply_to), href: to_charlist(get_href(in_reply_to))], []} + ] + else + _ -> + [] + end end - defp get_in_reply_to(_), do: [] - defp get_mentions(to) do Enum.map(to, fn id -> cond do @@ -98,7 +101,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do []} 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: [] mentions = activity.recipients |> get_mentions diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs index a4bb68c4d..16ee02abb 100644 --- a/test/web/ostatus/activity_representer_test.exs +++ b/test/web/ostatus/activity_representer_test.exs @@ -67,37 +67,31 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do end test "a reply note" do - note = insert(:note_activity) - answer = insert(:note_activity) - object = answer.data["object"] - object = Map.put(object, "inReplyTo", note.data["object"]["id"]) - - data = %{answer.data | "object" => object} - answer = %{answer | data: data} - - note_object = Object.get_by_ap_id(note.data["object"]["id"]) + user = insert(:user) + note_object = insert(:note) + _note = insert(:note_activity, %{note: note_object}) + object = insert(:note, %{data: %{"inReplyTo" => note_object.data["id"]}}) + answer = insert(:note_activity, %{note: object}) Repo.update!( Object.change(note_object, %{data: Map.put(note_object.data, "external_url", "someurl")}) ) - user = User.get_cached_by_ap_id(answer.data["actor"]) - expected = """ http://activitystrea.ms/schema/1.0/note http://activitystrea.ms/schema/1.0/post - #{answer.data["object"]["id"]} + #{object.data["id"]} New note by #{user.nickname} - #{answer.data["object"]["content"]} - #{answer.data["object"]["published"]} - #{answer.data["object"]["published"]} + #{object.data["content"]} + #{object.data["published"]} + #{object.data["published"]} #{answer.data["context"]} 2hu - - + + - + """ From 1d78e42fd4ca73402c4101ac01b9abb44f4f8cf6 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 10 May 2019 13:49:34 +0300 Subject: [PATCH 2/2] Remove get_in_reply_to calls in some functions because the result is unused and it does not have any side-effects --- lib/pleroma/web/ostatus/activity_representer.ex | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index a7832a3d9..95037125d 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -149,7 +149,6 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do updated_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: [] mentions = activity.recipients |> get_mentions @@ -180,7 +179,6 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do updated_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: [] retweeted_activity = Activity.get_create_by_object_ap_id(activity.data["object"])