From 17d42f847605aa073bc0858ba1f05879c2a53c17 Mon Sep 17 00:00:00 2001 From: Pierre de Lacroix Date: Thu, 11 Jun 2020 07:04:36 +0200 Subject: bugfixes --- .../controllers/v1/room_controller.ex | 11 ++++++-- .../controllers/v1/transaction_controller.ex | 31 +++++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/lib/matrix_app_service_web/controllers/v1/room_controller.ex b/lib/matrix_app_service_web/controllers/v1/room_controller.ex index 3729708..17cbac0 100644 --- a/lib/matrix_app_service_web/controllers/v1/room_controller.ex +++ b/lib/matrix_app_service_web/controllers/v1/room_controller.ex @@ -1,7 +1,14 @@ defmodule MatrixAppServiceWeb.V1.RoomController do use MatrixAppServiceWeb, :controller - def show(conn, _params) do - send_resp(conn, 404, "") + def show(conn, %{"room_alias" => room_alias}) do + module = Application.fetch_env!(:matrix_app_service, :room_module) + + with :ok <- module.query_alias(room_alias) do + send_resp(conn, 200, "{}") + else + _ -> + send_resp(conn, 404, "") + end end end diff --git a/lib/matrix_app_service_web/controllers/v1/transaction_controller.ex b/lib/matrix_app_service_web/controllers/v1/transaction_controller.ex index 252cfc6..bbb0293 100644 --- a/lib/matrix_app_service_web/controllers/v1/transaction_controller.ex +++ b/lib/matrix_app_service_web/controllers/v1/transaction_controller.ex @@ -28,7 +28,7 @@ defmodule MatrixAppServiceWeb.V1.TransactionController do "unsigned" => unsigned, "user_id" => user_id }) do - module = Application.get_env(:matrix_app_service, :transaction_module) + module = Application.fetch_env!(:matrix_app_service, :transaction_module) event = %MatrixAppService.Event{ age: age, @@ -46,6 +46,35 @@ defmodule MatrixAppServiceWeb.V1.TransactionController do module.new_event(event) end + defp create_event(%{ + "age" => age, + "content" => content, + "event_id" => event_id, + "origin_server_ts" => origin_server_ts, + "room_id" => room_id, + "sender" => sender, + "type" => type, + "unsigned" => unsigned, + "user_id" => user_id + }) do + module = Application.fetch_env!(:matrix_app_service, :transaction_module) + + event = %MatrixAppService.Event{ + age: age, + content: content, + event_id: event_id, + origin_server_ts: origin_server_ts, + room_id: room_id, + sender: sender, + state_key: nil, + type: type, + unsigned: unsigned, + user_id: user_id + } + + module.new_event(event) + end + def create(conn, %{"events" => events}) do Enum.each(events, &create_event(&1)) send_resp(conn, 200, "{}") -- cgit v1.2.3