Return note objects as ostatus post activities.
authorRoger Braun <roger@rogerbraun.net>
Wed, 3 May 2017 07:54:17 +0000 (09:54 +0200)
committerRoger Braun <roger@rogerbraun.net>
Wed, 3 May 2017 07:54:17 +0000 (09:54 +0200)
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/ostatus/ostatus_controller.ex
lib/pleroma/web/router.ex
test/web/ostatus/ostatus_controller_test.exs

index 12d6912df06808c6e5078c9768706152b9390e42..194a5ec3d150d5a752ff9754c0dfd2c96c77c203 100644 (file)
@@ -126,7 +126,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
   end
 
   def generate_object_id do
-    generate_id("objects")
+    Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :object, Ecto.UUID.generate)
   end
 
   def generate_id(type) do
index 1c609f6f223611d3b56dcf84e6b735d067b3725d..6a4199846ba596d7833d856176d8f0bcbb0c596e 100644 (file)
@@ -41,4 +41,19 @@ defmodule Pleroma.Web.OStatus.OStatusController do
     conn
     |> send_resp(200, "")
   end
+
+  def object(conn, %{"uuid" => uuid}) do
+    IO.inspect(uuid)
+    id = o_status_url(conn, :object, uuid)
+    activity = Activity.get_create_activity_by_object_ap_id(id)
+    user = User.get_cached_by_ap_id(activity.data["actor"])
+
+    response = FeedRepresenter.to_simple_form(user, [activity], [user])
+    |> :xmerl.export_simple(:xmerl_xml)
+    |> to_string
+
+    conn
+    |> put_resp_content_type("application/atom+xml")
+    |> send_resp(200, response)
+  end
 end
index b0c1dcd9177b77990b11032141aaa69ee91d8bf7..ac9d97e0f558c9ed1a12c4d3e41119c85bc8e666 100644 (file)
@@ -73,6 +73,8 @@ defmodule Pleroma.Web.Router do
   scope "/", Pleroma.Web do
     pipe_through :ostatus
 
+    get "/objects/:uuid", OStatus.OStatusController, :object
+
     get "/users/:nickname/feed", OStatus.OStatusController, :feed
     get "/users/:nickname", OStatus.OStatusController, :feed_redirect
     post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming
@@ -96,5 +98,5 @@ end
 
 defmodule Fallback.RedirectController do
   use Pleroma.Web, :controller
-  def redirector(conn, _params), do: send_file(conn, 200, "priv/static/index.html")
+  def redirector(conn, _params), do: (if Mix.env != :test, do: send_file(conn, 200, "priv/static/index.html"))
 end
index 229cd9b1e1c214980eafdb8b00f4e6e4df8ce7bd..f076987474f0d89f33392378941402388c65b17f 100644 (file)
@@ -12,4 +12,16 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
 
     assert response(conn, 200)
   end
+
+  test "gets an object", %{conn: conn} do
+    note_activity = insert(:note_activity)
+    [_, uuid] = hd Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"])
+    url = "/objects/#{uuid}"
+    |> IO.inspect
+
+    conn = conn
+    |> get(url)
+
+    assert response(conn, 200)
+  end
 end