Add PerformJoin template

This commit is contained in:
Neil Alexander 2020-05-01 14:27:48 +01:00
parent f7cfa75886
commit 38513fb4ed
3 changed files with 88 additions and 0 deletions

59
roomserver/api/perform.go Normal file
View file

@ -0,0 +1,59 @@
package api
import (
"context"
commonHTTP "github.com/matrix-org/dendrite/common/http"
"github.com/opentracing/opentracing-go"
)
const (
// RoomserverPerformJoinPath is the HTTP path for the PerformJoinRequest API.
RoomserverPerformJoinPath = "/api/roomserver/performJoin"
// RoomserverPerformLeavePath is the HTTP path for the PerformLeaveRequest API.
RoomserverPerformLeavePath = "/api/roomserver/performLeave"
)
type PerformJoinRequest struct {
RoomID string `json:"room_id"`
UserID string `json:"user_id"`
Content map[string]interface{} `json:"content"`
}
type PerformJoinResponse struct {
}
// Handle an instruction to make_join & send_join with a remote server.
func (h *httpRoomserverInternalAPI) PerformJoin(
ctx context.Context,
request *PerformJoinRequest,
response *PerformJoinResponse,
) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformJoin")
defer span.Finish()
apiURL := h.roomserverURL + RoomserverPerformJoinPath
return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
}
type PerformLeaveRequest struct {
RoomID string `json:"room_id"`
UserID string `json:"user_id"`
}
type PerformLeaveResponse struct {
}
// Handle an instruction to make_leave & send_leave with a remote server.
func (h *httpRoomserverInternalAPI) PerformLeave(
ctx context.Context,
request *PerformLeaveRequest,
response *PerformLeaveResponse,
) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformLeave")
defer span.Finish()
apiURL := h.roomserverURL + RoomserverPerformLeavePath
return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
}

View file

@ -46,6 +46,19 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(api.RoomserverPerformJoinPath,
common.MakeInternalAPI("performJoin", func(req *http.Request) util.JSONResponse {
var request api.PerformJoinRequest
var response api.PerformJoinResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.MessageResponse(http.StatusBadRequest, err.Error())
}
if err := r.PerformJoin(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryLatestEventsAndStatePath,
common.MakeInternalAPI("queryLatestEventsAndState", func(req *http.Request) util.JSONResponse {

View file

@ -0,0 +1,16 @@
package internal
import (
"context"
"github.com/matrix-org/dendrite/roomserver/api"
)
// WriteOutputEvents implements OutputRoomEventWriter
func (r *RoomserverInternalAPI) PerformJoin(
ctx context.Context,
req *api.PerformJoinRequest,
res *api.PerformJoinResponse,
) error {
return nil
}