Refactor room server
Serialize and save room state in database Get room state from database when creating a room server
This commit is contained in:
parent
65368dc2d4
commit
9e02d5b95c
10 changed files with 122 additions and 146 deletions
|
@ -44,7 +44,7 @@ defmodule MatrixServerWeb.AuthController do
|
|||
|
||||
def register(conn, %{"auth" => _}) do
|
||||
# Other login types are unsupported for now.
|
||||
put_error(conn, :forbidden)
|
||||
put_error(conn, :unrecognized, "Only m.login.dummy is supported currently.")
|
||||
end
|
||||
|
||||
def register(conn, _params) do
|
||||
|
@ -87,8 +87,11 @@ defmodule MatrixServerWeb.AuthController do
|
|||
|> put_status(200)
|
||||
|> json(data)
|
||||
|
||||
{:error, error} ->
|
||||
{:error, error} when is_atom(error) ->
|
||||
put_error(conn, error)
|
||||
|
||||
{:error, _} ->
|
||||
put_error(conn, :unknown)
|
||||
end
|
||||
|
||||
_ ->
|
||||
|
@ -98,6 +101,6 @@ defmodule MatrixServerWeb.AuthController do
|
|||
|
||||
def login(conn, _params) do
|
||||
# Other login types and identifiers are unsupported for now.
|
||||
put_error(conn, :unknown)
|
||||
put_error(conn, :unrecognized, "Only m.login.password is supported currently.")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,9 +15,10 @@ defmodule MatrixServerWeb.RoomController do
|
|||
input = apply_changes(cs)
|
||||
|
||||
# TODO: refactor
|
||||
%Room{id: room_id} = Repo.insert!(Room.create_changeset(input))
|
||||
{:ok, pid} = RoomServer.get_room_server(room_id)
|
||||
RoomServer.create_room(pid, account, input)
|
||||
# Room.create(account, input)
|
||||
# %Room{id: room_id} = Repo.insert!(Room.create_changeset(input))
|
||||
# {:ok, pid} = RoomServer.get_room_server(room_id)
|
||||
# RoomServer.create_room(pid, account, input)
|
||||
|
||||
conn
|
||||
|> put_status(200)
|
||||
|
|
|
@ -2,7 +2,7 @@ defmodule MatrixServerWeb.Plug.Error do
|
|||
import Plug.Conn
|
||||
import Phoenix.Controller, only: [json: 2]
|
||||
|
||||
@error_code_and_message %{
|
||||
@error_map %{
|
||||
bad_json: {400, "M_BAD_JSON", "Bad request."},
|
||||
user_in_use: {400, "M_USER_IN_USE", "Username is already taken."},
|
||||
invalid_username: {400, "M_INVALID_USERNAME", "Invalid username."},
|
||||
|
@ -13,9 +13,9 @@ defmodule MatrixServerWeb.Plug.Error do
|
|||
missing_token: {401, "M_MISSING_TOKEN", "Access token required."}
|
||||
}
|
||||
|
||||
def put_error(conn, error) do
|
||||
{status, errcode, errmsg} = @error_code_and_message[error]
|
||||
data = %{errcode: errcode, error: errmsg}
|
||||
def put_error(conn, error, msg \\ nil) do
|
||||
{status, errcode, default_msg} = @error_map[error]
|
||||
data = %{errcode: errcode, error: msg or default_msg}
|
||||
|
||||
conn
|
||||
|> put_status(status)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue