Implement retrieving a single event over federation
Fix url encoding during homeserver signature check
This commit is contained in:
parent
1881b7f3d6
commit
e510c3bb6a
14 changed files with 173 additions and 22 deletions
|
@ -2,9 +2,44 @@ defmodule MatrixServerWeb.Federation.EventController do
|
|||
use MatrixServerWeb, :controller
|
||||
use MatrixServerWeb.Federation.AuthenticateServer
|
||||
|
||||
def event(conn, %{"event_id" => _event_id}) do
|
||||
conn
|
||||
|> put_status(200)
|
||||
|> json(%{})
|
||||
import MatrixServerWeb.Error
|
||||
import Ecto.Query
|
||||
|
||||
alias MatrixServer.{Repo, Event, RoomServer}
|
||||
alias MatrixServerWeb.Federation.Transaction
|
||||
|
||||
def event(%Plug.Conn{assigns: %{origin: origin}} = conn, %{"event_id" => event_id}) do
|
||||
query =
|
||||
Event
|
||||
|> where([e], e.event_id == ^event_id)
|
||||
|> preload(:room)
|
||||
|
||||
case Repo.one(query) do
|
||||
%Event{room: room} = event ->
|
||||
case RoomServer.get_room_server(room) do
|
||||
{:ok, pid} ->
|
||||
if RoomServer.server_in_room(pid, origin) do
|
||||
data = Transaction.new([event])
|
||||
|
||||
conn
|
||||
|> put_status(200)
|
||||
|> json(data)
|
||||
else
|
||||
put_error(
|
||||
conn,
|
||||
:unauthorized,
|
||||
"Origin server is not allowed to see requested event."
|
||||
)
|
||||
end
|
||||
|
||||
_ ->
|
||||
put_error(conn, :unknown)
|
||||
end
|
||||
|
||||
nil ->
|
||||
put_error(conn, :not_found, "Event or room not found.")
|
||||
end
|
||||
end
|
||||
|
||||
def event(conn, _), do: put_error(conn, :bad_json)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue