Implement client leave endpoint

Add documentation and type specs
This commit is contained in:
Pim Kunis 2021-08-26 11:01:19 +02:00
parent a1475c1a46
commit ae860a768c
9 changed files with 140 additions and 28 deletions

View file

@ -112,4 +112,29 @@ defmodule MatrixServerWeb.Client.RoomController do
end
def join(conn, _), do: put_error(conn, :missing_param)
@doc """
This API stops a user participating in a particular room.
Action for POST /_matrix/client/r0/rooms/{roomId}/leave.
"""
def leave(%Conn{assigns: %{account: account}} = conn, %{"room_id" => room_id}) do
case RoomServer.get_room_server(room_id) do
{:ok, pid} ->
case RoomServer.leave(pid, account) do
:ok ->
conn
|> send_resp(200, [])
|> halt()
{:error, _} ->
put_error(conn, :unknown)
end
{:error, :not_found} ->
put_error(conn, :not_found, "The given room was not found.")
end
end
def leave(conn, _), do: put_error(conn, :missing_param)
end

View file

@ -3,6 +3,13 @@ defmodule MatrixServerWeb.Client.Request.Login do
import Ecto.Changeset
@type t :: %__MODULE__{
type: String.t(),
password: String.t(),
device_id: String.t(),
initial_device_display_name: String.t()
}
@primary_key false
embedded_schema do
field :type, :string

View file

@ -5,6 +5,14 @@ defmodule MatrixServerWeb.Client.Request.Register do
alias Ecto.Changeset
@type t :: %__MODULE__{
device_id: String.t(),
initial_device_display_name: String.t(),
password: String.t(),
username: String.t(),
inhibit_login: boolean()
}
@primary_key false
embedded_schema do
field :device_id, :string