summaryrefslogtreecommitdiff
path: root/lib/matrix_app_service
diff options
context:
space:
mode:
Diffstat (limited to 'lib/matrix_app_service')
-rw-r--r--lib/matrix_app_service/application.ex23
-rw-r--r--lib/matrix_app_service/client.ex27
2 files changed, 39 insertions, 11 deletions
diff --git a/lib/matrix_app_service/application.ex b/lib/matrix_app_service/application.ex
index 38f65be..383c0f9 100644
--- a/lib/matrix_app_service/application.ex
+++ b/lib/matrix_app_service/application.ex
@@ -18,9 +18,10 @@ defmodule MatrixAppService.Application do
]
children =
- if Mix.env() == :test do
+ if start_endpoint?() do
[
- MatrixAppServiceWeb.TestEndpoint
+ # MatrixAppServiceWeb.Endpoint
+ {MatrixAppServiceWeb.Endpoint, endpoint_config()}
| children
]
else
@@ -36,10 +37,26 @@ defmodule MatrixAppService.Application do
# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
def config_change(changed, _new, removed) do
- if Application.get_env(:matrix_app_service, :standalone, false) do
+ if start_endpoint?() do
MatrixAppServiceWeb.Endpoint.config_change(changed, removed)
end
:ok
end
+
+ def start_endpoint?() do
+ Application.get_env(:matrix_app_service, :internal_supervisor, false)
+ end
+
+ def endpoint_config() do
+ [
+ transaction_adapter: Application.fetch_env!(:matrix_app_service, :transaction_adapter),
+ room_adapter: Application.fetch_env!(:matrix_app_service, :room_adapter),
+ user_adapter: Application.fetch_env!(:matrix_app_service, :user_adapter),
+ homeserver_token: Application.fetch_env!(:matrix_app_service, :homeserver_token),
+ access_token: Application.fetch_env!(:matrix_app_service, :access_token),
+ base_url: Application.fetch_env!(:matrix_app_service, :base_url),
+ path: Application.get_env(:matrix_app_service, :path, "/")
+ ]
+ end
end
diff --git a/lib/matrix_app_service/client.ex b/lib/matrix_app_service/client.ex
index 42ef758..cec1046 100644
--- a/lib/matrix_app_service/client.ex
+++ b/lib/matrix_app_service/client.ex
@@ -24,10 +24,21 @@ defmodule MatrixAppService.Client do
Polyjuice.Client.LowLevel.t()
def client(opts \\ []) do
base_url =
- Keyword.get(opts, :base_url, Application.fetch_env!(:matrix_app_service, :base_url))
+ Keyword.get(opts, :base_url) ||
+ (MatrixAppService.Application.start_endpoint?() &&
+ MatrixAppServiceWeb.Endpoint.config(:base_url)) ||
+ Application.get_env(:matrix_app_service, :app_service)[:base_url] ||
+ raise "MatrixAppService: config key base_url missing"
+
+ access_token =
+ Keyword.get(opts, :access_token) ||
+ (MatrixAppService.Application.start_endpoint?() &&
+ MatrixAppServiceWeb.Endpoint.config(:access_token)) ||
+ Application.get_env(:matrix_app_service, :app_service)[:access_token] ||
+ raise "MatrixAppService: config key access_token missing"
default_opts = [
- access_token: Application.fetch_env!(:matrix_app_service, :access_token),
+ access_token: access_token,
device_id: "APP_SERVICE"
]
@@ -82,12 +93,12 @@ defmodule MatrixAppService.Client do
Arguments:
1. `opts`: a keyword list that can contain these keys:
- * `:inhibit_login`: true
- * `:device_id`: device ID, defaults to `"APP_SERVICE"`
- * `:initial_device_display_name`: device name, defaults to
- `"ApplicationService"`
- * `:kind`: kind of account to register, defaults to `"user"`, can also be
- `"guest"`
+ * `:inhibit_login`: true
+ * `:device_id`: device ID, defaults to `"APP_SERVICE"`
+ * `:initial_device_display_name`: device name, defaults to
+ `"ApplicationService"`
+ * `:kind`: kind of account to register, defaults to `"user"`, can also be
+ `"guest"`
2. `client_options`: see `client/1`
"""
@spec register(Polyjuice.Client.LowLevel.register_opts(), client_options()) ::