Also show activities in OStatus.
authorRoger Braun <roger@rogerbraun.net>
Fri, 19 May 2017 13:53:02 +0000 (15:53 +0200)
committerRoger Braun <roger@rogerbraun.net>
Fri, 19 May 2017 13:53:02 +0000 (15:53 +0200)
lib/pleroma/web/ostatus/ostatus_controller.ex
lib/pleroma/web/router.ex
test/web/ostatus/ostatus_controller_test.exs

index e6822463d534a1a44d20e1bdbb9f3153d3f8c29a..fd8dcdf5237466f4178173e75c28acbfb8514405 100644 (file)
@@ -44,10 +44,22 @@ defmodule Pleroma.Web.OStatus.OStatusController do
   end
 
   def object(conn, %{"uuid" => uuid}) do
-    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"])
+    with id <- o_status_url(conn, :object, uuid),
+         %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id),
+         %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
+      represent_activity(conn, activity, user)
+    end
+  end
+
+  def activity(conn, %{"uuid" => uuid}) do
+    with id <- o_status_url(conn, :activity, uuid),
+         %Activity{} = activity <- Activity.get_by_ap_id(id),
+         %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
+      represent_activity(conn, activity, user)
+    end
+  end
 
+  defp represent_activity(conn, activity, user) do
     response = activity
     |> ActivityRepresenter.to_simple_form(user, true)
     |> ActivityRepresenter.wrap_with_entry
index 15f66b24f95ae2edf9abb7e786b384ba7856af59..12159cffc16bd38d70f8cc97e0f45312cb2b473f 100644 (file)
@@ -77,6 +77,7 @@ defmodule Pleroma.Web.Router do
     pipe_through :ostatus
 
     get "/objects/:uuid", OStatus.OStatusController, :object
+    get "/activities/:uuid", OStatus.OStatusController, :activity
 
     get "/users/:nickname/feed", OStatus.OStatusController, :feed
     get "/users/:nickname", OStatus.OStatusController, :feed_redirect
index 8b7ca4d8933dcbbe5191ebf6d98672a79a7637a8..77bc202fefccaf29e7caec4a73ebdd03ca1f3613 100644 (file)
@@ -2,6 +2,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
   use Pleroma.Web.ConnCase
   import Pleroma.Factory
   alias Pleroma.User
+  alias Pleroma.Web.OStatus.ActivityRepresenter
 
   test "gets a feed", %{conn: conn} do
     note_activity = insert(:note_activity)
@@ -15,12 +16,29 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
 
   test "gets an object", %{conn: conn} do
     note_activity = insert(:note_activity)
+    user = User.get_by_ap_id(note_activity.data["actor"])
     [_, uuid] = hd Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"])
     url = "/objects/#{uuid}"
 
     conn = conn
     |> get(url)
 
+    expected = ActivityRepresenter.to_simple_form(note_activity, user, true)
+    |> ActivityRepresenter.wrap_with_entry
+    |> :xmerl.export_simple(:xmerl_xml)
+    |> to_string
+
+    assert response(conn, 200) == expected
+  end
+
+  test "gets an activity", %{conn: conn} do
+    note_activity = insert(:note_activity)
+    [_, uuid] = hd Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"])
+    url = "/activities/#{uuid}"
+
+    conn = conn
+    |> get(url)
+
     assert response(conn, 200)
   end
 end