summaryrefslogtreecommitdiff
path: root/lib/matrix_app_service_web/controllers/v1/transaction_controller.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/matrix_app_service_web/controllers/v1/transaction_controller.ex')
-rw-r--r--lib/matrix_app_service_web/controllers/v1/transaction_controller.ex51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/matrix_app_service_web/controllers/v1/transaction_controller.ex b/lib/matrix_app_service_web/controllers/v1/transaction_controller.ex
new file mode 100644
index 0000000..a71b497
--- /dev/null
+++ b/lib/matrix_app_service_web/controllers/v1/transaction_controller.ex
@@ -0,0 +1,51 @@
+defmodule MatrixAppServiceWeb.V1.TransactionController do
+ use MatrixAppServiceWeb, :controller
+
+ # %{"access_token" => access_token,
+ # "events" => [
+ # %{"age" => 199,
+ # "content" => %{
+ # "body" => "test",
+ # "msgtype" => "m.room.message"},
+ # "event_id" => "$pMDN7TcsCapjLRYoITwryk0anpQGs60y2Eng3lxropc",
+ # "origin_server_ts" => 1588950428966,
+ # "room_id" => "!SrVtqmyqzuaMnfVImP:matrix.imago.local",
+ # "sender" => "@alice:matrix.imago.local",
+ # "type" => "m.room.message",
+ # "unsigned" => %{"age" => 199},
+ # "user_id" => "@alice:matrix.imago.local"}],
+ # "txn_id" => "269"}
+
+ 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.get_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,
+ 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, "{}")
+ end
+end