Implement client leave endpoint
Add documentation and type specs
This commit is contained in:
parent
a1475c1a46
commit
ae860a768c
9 changed files with 140 additions and 28 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -60,6 +60,7 @@ defmodule MatrixServerWeb.Router do
|
|||
scope "/rooms/:room_id" do
|
||||
post "/invite", RoomController, :invite
|
||||
post "/join", RoomController, :join
|
||||
post "/leave", RoomController, :leave
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue