Add href to in-reply-to.
authorRoger Braun <roger@rogerbraun.net>
Tue, 1 Aug 2017 15:35:19 +0000 (17:35 +0200)
committerRoger Braun <roger@rogerbraun.net>
Tue, 1 Aug 2017 15:35:19 +0000 (17:35 +0200)
THis should enable fetching from pleroma posts.

lib/pleroma/web/ostatus/activity_representer.ex
test/web/ostatus/activity_representer_test.exs

index a129fac23c5a1b28e86f3bf00cbe766eca34293f..842e44ee4aa25dc909a5ca379dc4adaf753f35ca 100644 (file)
@@ -1,10 +1,18 @@
 defmodule Pleroma.Web.OStatus.ActivityRepresenter do
-  alias Pleroma.{Activity, User}
+  alias Pleroma.{Activity, User, Object}
   alias Pleroma.Web.OStatus.UserRepresenter
   require Logger
 
+  defp get_href(id) do
+    with %Object{data: %{ "external_url" => external_url } }<- Object.get_cached_by_ap_id(id) do
+      external_url
+    else
+      _e -> id
+    end
+  end
+
   defp get_in_reply_to(%{"object" => %{"inReplyTo" => in_reply_to}}) do
-    [{:"thr:in-reply-to", [ref: to_charlist(in_reply_to)], []}]
+    [{:"thr:in-reply-to", [ref: to_charlist(in_reply_to), href: to_charlist(get_href(in_reply_to))], []}]
   end
 
   defp get_in_reply_to(_), do: []
index 171a8bae75e6fe20cc3d5df42592df50de9e26e8..0129e375855625fb72ffd668823a50cf3837167e 100644 (file)
@@ -58,6 +58,9 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
     data = %{answer.data | "object" => object}
     answer = %{answer | data: data}
 
+    note_object = Object.get_by_ap_id(note.data["object"]["id"])
+    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 = """
@@ -73,7 +76,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
     <link type="application/atom+xml" href="#{answer.data["object"]["id"]}" rel="self" />
     <link type="text/html" href="#{answer.data["object"]["id"]}" rel="alternate" />
     <category term="2hu"/>
-    <thr:in-reply-to ref="#{note.data["object"]["id"]}" />
+    <thr:in-reply-to ref="#{note.data["object"]["id"]}" href="someurl" />
     <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
     """