Conversation: Add endpoint to get a conversation by id.
authorlain <lain@soykaf.club>
Mon, 12 Aug 2019 11:58:04 +0000 (13:58 +0200)
committerlain <lain@soykaf.club>
Mon, 12 Aug 2019 11:58:04 +0000 (13:58 +0200)
docs/api/pleroma_api.md
lib/pleroma/web/pleroma_api/pleroma_api_controller.ex
lib/pleroma/web/router.ex
test/web/pleroma_api/pleroma_api_controller_test.exs

index 590f2a3fb7e140c5a064e86d706d45ca8324297c..b134b31a8421b4068c81d4f11c9a33e910413041 100644 (file)
@@ -340,6 +340,12 @@ The status posting endpoint takes an additional parameter, `in_reply_to_conversa
 * Params: Like other timelines
 * Response: JSON, statuses (200 - healthy, 503 unhealthy).
 
+## `GET /api/v1/pleroma/conversations/:id`
+### The conversation with the given ID.
+* Method `GET`
+* Authentication: required
+* Params: None
+* Response: JSON, statuses (200 - healthy, 503 unhealthy).
 
 ## `PATCH /api/v1/pleroma/conversations/:id`
 ### Update a conversation. Used to change the set of recipients.
index 0185644521f93c8beaa71f52b2c5386e01dc8474..3175a99b16c3e98a619e7c6a511820b88c616e7b 100644 (file)
@@ -13,6 +13,15 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do
   alias Pleroma.Web.MastodonAPI.ConversationView
   alias Pleroma.Web.MastodonAPI.StatusView
 
+  def conversation(%{assigns: %{user: user}} = conn, %{"id" => participation_id}) do
+    with %Participation{} = participation <- Participation.get(participation_id),
+         true <- user.id == participation.user_id do
+      conn
+      |> put_view(ConversationView)
+      |> render("participation.json", %{participation: participation, user: user})
+    end
+  end
+
   def conversation_statuses(
         %{assigns: %{user: user}} = conn,
         %{"id" => participation_id} = params
index c835f06b456d89096b0b6d392130982eb91d1887..f0b6a02e98a40ef9a1ebbffc14df1cbbeb1cdf88 100644 (file)
@@ -265,6 +265,7 @@ defmodule Pleroma.Web.Router do
     scope [] do
       pipe_through(:oauth_write)
       get("/conversations/:id/statuses", PleromaAPIController, :conversation_statuses)
+      get("/conversations/:id", PleromaAPIController, :conversation)
       patch("/conversations/:id", PleromaAPIController, :update_conversation)
     end
   end
index 56bc1572cc8ca2ca8f54cc83ed69e6c0c203ad4a..ed6b797272098fdbfa0c50431a7d7dc7fb9de691 100644 (file)
@@ -11,6 +11,24 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
 
   import Pleroma.Factory
 
+  test "/api/v1/pleroma/conversations/:id", %{conn: conn} do
+    user = insert(:user)
+    other_user = insert(:user)
+
+    {:ok, _activity} =
+      CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
+
+    [participation] = Participation.for_user(other_user)
+
+    result =
+      conn
+      |> assign(:user, other_user)
+      |> get("/api/v1/pleroma/conversations/#{participation.id}")
+      |> json_response(200)
+
+    assert result["id"] == participation.id |> to_string()
+  end
+
   test "/api/v1/pleroma/conversations/:id/statuses", %{conn: conn} do
     user = insert(:user)
     other_user = insert(:user)