Verified Commit d347343e authored by Nicolas's avatar Nicolas

- Added `GET /_matrix/client/r0/capabilities` endpoint (currently hardcoded)

- Initialize sync and pushrules controllers
parent 1c1b2f74
......@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Added
#### 2019-12-29
- Refactor Users, Device and access token management
- Added `GET /_matrix/client/r0/capabilities` endpoint (currently hardcoded)
- Initialize sync and pushrules controllers
#### 2019-05-23
- API: Implement filtering endpoints
......
......@@ -54,6 +54,9 @@ Plasma currently implements the following API endpoints
#### Current account information
- [X] `GET /_matrix/client/r0/account/whoami`
#### Capabilities negotiation
- [X] `GET /_matrix/client/r0/capabilities`
#### Filtering
- [X] `POST /_matrix/client/r0/user/{userId}/filter`
- [X] `GET /_matrix/client/r0/user/{userId}/filter/{filterId}`
......
defmodule PlasmaHS.Controllers.MatrixApi.Client.R0.CapabilitiesController do
use PlasmaHS, :controller
use PlasmaHS.Controllers.MatrixApi.MatrixController
require Logger
def get_capabilities(conn, _params) do
Logger.warn("Get capabilities response is hardcoded")
conn |> json(%{
"capabilities" => %{
"m.change.password" => %{
"enabled" => false
},
"m.room_versions" => %{
"default" => "1",
"available"=> %{
"1" => "unstable",
"2" => "unstable",
"3" => "unstable",
"4" => "unstable",
"5" => "unstable"
}
}
}
})
end
end
\ No newline at end of file
......@@ -2,15 +2,18 @@ defmodule PlasmaHS.Controllers.MatrixApi.Client.R0.PushRules do
use PlasmaHS, :controller
use PlasmaHS.Controllers.MatrixApi.MatrixController
alias PlasmaRepo.Channels.Identifier
alias PlasmaRepo.Users
alias PlasmaRepo.Users.User
require Logger
@matrix_config Application.get_env(:homeserver, :matrix)
@matrix_config Application.get_env(:plasma, :matrix)
@default_content_rules @matrix_config[:default_content_rules]
@default_override_rules @matrix_config[:default_override_rules]
def get_push_rules(conn, _params) do
with %{user_id: user_id} <- conn.assigns,
{:ok, user_identifier} <- Identifier.parse(user_id) do
%User{} = user <- Users.get_with_devices(user_id),
{:ok, user_identifier} <- Identifier.parse(user.mx_user_id) do
conn |> json(%{
"global" => %{
"content" => personalize_rules(@default_content_rules, user_identifier),
......@@ -21,8 +24,8 @@ defmodule PlasmaHS.Controllers.MatrixApi.Client.R0.PushRules do
}
})
else
_ ->
Logger.error("Invalid user_id stored in connection assigns: #{inspect conn.assigns}")
errors ->
Logger.error("Invalid user_id stored in connection assigns: #{inspect conn.assigns}, #{errors}")
conn |> json_error(:p_internal_error)
end
end
......
defmodule PlasmaHS.Controllers.MatrixApi.Client.R0.Pushers do
use PlasmaHS, :controller
use PlasmaHS.Controllers.MatrixApi.MatrixController
alias PlasmaRepo.Channels.Identifier
require Logger
def get_pushers(conn, _params) do
conn |> json(%{})
end
end
\ No newline at end of file
defmodule PlasmaHS.Controllers.MatrixApi.Client.R0.SyncController do
use PlasmaHS, :controller
use PlasmaHS.Controllers.MatrixApi.MatrixController
alias PlasmaRepo.Channels.Identifier
require Logger
def get_sync(conn, _params) do
conn |> json(%{})
end
end
\ No newline at end of file
......@@ -27,6 +27,7 @@ defmodule PlasmaHS.Router do
get "/login", Login, :get
post "/login", Login, :login
get "/register/available", Register, :available
get "/sync", SyncController, :get_sync
end
end
......@@ -42,6 +43,7 @@ defmodule PlasmaHS.Router do
pipe_through [:api, :auth]
scope "/r0", R0 do
get "/capabilities", CapabilitiesController, :get_capabilities
post "/logout", Login, :logout
post "/logout/all", Login, :logout_all
post "/account/whoami", Account, :whoami
......@@ -52,6 +54,10 @@ defmodule PlasmaHS.Router do
get "/", PushRules, :get_push_rules
end
scope "/pushers" do
get "/", Pushers, :get_pushers
end
scope "/user" do
post "/:userId/filter", UserController, :post_filter
get "/:userId/filter/:filterId", UserController, :get_filter
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment