mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 17:33:09 -06:00
Start adding make/send_join apis
This commit is contained in:
parent
0786318a04
commit
0b803b4789
|
|
@ -0,0 +1,93 @@
|
||||||
|
// Copyright 2017 New Vector Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package routing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
|
"github.com/matrix-org/dendrite/common"
|
||||||
|
"github.com/matrix-org/dendrite/common/config"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
func MakeJoin(
|
||||||
|
ctx context.Context,
|
||||||
|
httpReq *http.Request,
|
||||||
|
request *gomatrixserverlib.FederationRequest,
|
||||||
|
cfg config.Dendrite,
|
||||||
|
query api.RoomserverQueryAPI,
|
||||||
|
now time.Time,
|
||||||
|
keys gomatrixserverlib.KeyRing,
|
||||||
|
roomID, userID string,
|
||||||
|
) util.JSONResponse {
|
||||||
|
builder := gomatrixserverlib.EventBuilder{
|
||||||
|
Sender: userID,
|
||||||
|
RoomID: roomID,
|
||||||
|
Type: "m.room.member",
|
||||||
|
StateKey: &userID,
|
||||||
|
}
|
||||||
|
err := builder.SetContent(map[string]interface{}{"membership": "join"})
|
||||||
|
if err != nil {
|
||||||
|
return httputil.LogThenError(httpReq, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var queryRes api.QueryLatestEventsAndStateResponse
|
||||||
|
event, err := common.BuildEvent(ctx, &builder, cfg, query, &queryRes)
|
||||||
|
if err == common.ErrRoomNoExists {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: 404,
|
||||||
|
JSON: jsonerror.NotFound("Room does not exist"),
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
return httputil.LogThenError(httpReq, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// check to see if this user can perform this operation
|
||||||
|
stateEvents := make([]*gomatrixserverlib.Event, len(queryRes.StateEvents))
|
||||||
|
for i := range queryRes.StateEvents {
|
||||||
|
stateEvents[i] = &queryRes.StateEvents[i]
|
||||||
|
}
|
||||||
|
provider := gomatrixserverlib.NewAuthEvents(stateEvents)
|
||||||
|
if err = gomatrixserverlib.Allowed(*event, &provider); err != nil {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: 403,
|
||||||
|
JSON: jsonerror.Forbidden(err.Error()), // TODO: Is this error string comprehensible to the client?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: 200,
|
||||||
|
JSON: event,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SendJoin(
|
||||||
|
ctx context.Context,
|
||||||
|
httpReq *http.Request,
|
||||||
|
request *gomatrixserverlib.FederationRequest,
|
||||||
|
cfg config.Dendrite,
|
||||||
|
query api.RoomserverQueryAPI,
|
||||||
|
now time.Time,
|
||||||
|
keys gomatrixserverlib.KeyRing,
|
||||||
|
roomID, eventID string,
|
||||||
|
) util.JSONResponse {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -124,6 +124,18 @@ func Setup(
|
||||||
},
|
},
|
||||||
)).Methods("GET")
|
)).Methods("GET")
|
||||||
|
|
||||||
|
v1fedmux.Handle("/make_join/{roomID}/{userID}", common.MakeFedAPI(
|
||||||
|
"federation_make_join", cfg.Matrix.ServerName, keys,
|
||||||
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||||
|
vars := mux.Vars(httpReq)
|
||||||
|
roomID := vars["roomID"]
|
||||||
|
userID := vars["userID"]
|
||||||
|
return MakeJoin(
|
||||||
|
httpReq.Context(), httpReq, request, cfg, query, time.Now(), keys, roomID, userID,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)).Methods("GET")
|
||||||
|
|
||||||
v1fedmux.Handle("/version", common.MakeExternalAPI(
|
v1fedmux.Handle("/version", common.MakeExternalAPI(
|
||||||
"federation_version",
|
"federation_version",
|
||||||
func(httpReq *http.Request) util.JSONResponse {
|
func(httpReq *http.Request) util.JSONResponse {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue