diff options
| author | lain <lain@soykaf.club> | 2020-05-10 13:26:14 +0200 | 
|---|---|---|
| committer | lain <lain@soykaf.club> | 2020-05-10 13:26:14 +0200 | 
| commit | 8d5597ff68de22ee7b126730467649ada248aaf7 (patch) | |
| tree | 9e9f904f82d7cec6d5e42fe79492f8a9750fe066 /lib | |
| parent | 172d9b11936bb029093eac430c58c89a81592c08 (diff) | |
| download | pleroma-8d5597ff68de22ee7b126730467649ada248aaf7.tar.gz pleroma-8d5597ff68de22ee7b126730467649ada248aaf7.zip | |
ChatController: Add GET /chats/:id
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pleroma/web/api_spec/operations/chat_operation.ex | 31 | ||||
| -rw-r--r-- | lib/pleroma/web/api_spec/schemas/chat.ex | 2 | ||||
| -rw-r--r-- | lib/pleroma/web/api_spec/schemas/chat_message.ex | 1 | ||||
| -rw-r--r-- | lib/pleroma/web/pleroma_api/controllers/chat_controller.ex | 10 | ||||
| -rw-r--r-- | lib/pleroma/web/router.ex | 1 | 
5 files changed, 43 insertions, 2 deletions
| diff --git a/lib/pleroma/web/api_spec/operations/chat_operation.ex b/lib/pleroma/web/api_spec/operations/chat_operation.ex index 16d3d5e22..fe6c2f52f 100644 --- a/lib/pleroma/web/api_spec/operations/chat_operation.ex +++ b/lib/pleroma/web/api_spec/operations/chat_operation.ex @@ -38,6 +38,37 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do      }    end +  def show_operation do +    %Operation{ +      tags: ["chat"], +      summary: "Create a chat", +      operationId: "ChatController.show", +      parameters: [ +        Operation.parameter( +          :id, +          :path, +          :string, +          "The id of the chat", +          required: true, +          example: "1234" +        ) +      ], +      responses: %{ +        200 => +          Operation.response( +            "The existing chat", +            "application/json", +            Chat +          ) +      }, +      security: [ +        %{ +          "oAuth" => ["read"] +        } +      ] +    } +  end +    def create_operation do      %Operation{        tags: ["chat"], diff --git a/lib/pleroma/web/api_spec/schemas/chat.ex b/lib/pleroma/web/api_spec/schemas/chat.ex index 8aaa4a792..c6ec07c88 100644 --- a/lib/pleroma/web/api_spec/schemas/chat.ex +++ b/lib/pleroma/web/api_spec/schemas/chat.ex @@ -16,7 +16,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Chat do        id: %Schema{type: :string},        account: %Schema{type: :object},        unread: %Schema{type: :integer}, -      last_message: %Schema{type: ChatMessage, nullable: true} +      last_message: ChatMessage      },      example: %{        "account" => %{ diff --git a/lib/pleroma/web/api_spec/schemas/chat_message.ex b/lib/pleroma/web/api_spec/schemas/chat_message.ex index 89e062ddd..6e8f1a10a 100644 --- a/lib/pleroma/web/api_spec/schemas/chat_message.ex +++ b/lib/pleroma/web/api_spec/schemas/chat_message.ex @@ -10,6 +10,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.ChatMessage do    OpenApiSpex.schema(%{      title: "ChatMessage",      description: "Response schema for a ChatMessage", +    nullable: true,      type: :object,      properties: %{        id: %Schema{type: :string}, diff --git a/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex b/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex index 1ef3477c8..04f136dcd 100644 --- a/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex @@ -27,7 +27,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do    plug(      OAuthScopesPlug, -    %{scopes: ["read:statuses"]} when action in [:messages, :index] +    %{scopes: ["read:statuses"]} when action in [:messages, :index, :show]    )    plug(OpenApiSpex.Plug.CastAndValidate, render_error: Pleroma.Web.ApiSpec.RenderError) @@ -100,4 +100,12 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do        |> render("show.json", chat: chat)      end    end + +  def show(%{assigns: %{user: user}} = conn, params) do +    with %Chat{} = chat <- Repo.get_by(Chat, user_id: user.id, id: params[:id]) do +      conn +      |> put_view(ChatView) +      |> render("show.json", chat: chat) +    end +  end  end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 4b264c43e..3b1834d97 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -307,6 +307,7 @@ defmodule Pleroma.Web.Router do        post("/chats/by-account-id/:id", ChatController, :create)        get("/chats", ChatController, :index) +      get("/chats/:id", ChatController, :show)        get("/chats/:id/messages", ChatController, :messages)        post("/chats/:id/messages", ChatController, :post_chat_message)        post("/chats/:id/read", ChatController, :mark_as_read) | 
