mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 09:23:09 -06:00
Wire up producers
This commit is contained in:
parent
0613cc3192
commit
16dae95478
|
|
@ -22,6 +22,7 @@ import (
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/producers"
|
||||||
"github.com/matrix-org/dendrite/common"
|
"github.com/matrix-org/dendrite/common"
|
||||||
"github.com/matrix-org/dendrite/common/config"
|
"github.com/matrix-org/dendrite/common/config"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
|
@ -39,13 +40,27 @@ func MakeJoin(
|
||||||
keys gomatrixserverlib.KeyRing,
|
keys gomatrixserverlib.KeyRing,
|
||||||
roomID, userID string,
|
roomID, userID string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
|
_, domain, err := gomatrixserverlib.SplitID('@', userID)
|
||||||
|
if err != nil {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: 400,
|
||||||
|
JSON: jsonerror.BadJSON("Invalid UserID"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if domain != request.Origin() {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: 403,
|
||||||
|
JSON: jsonerror.Forbidden("The join must be sent by the server of the user"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
builder := gomatrixserverlib.EventBuilder{
|
builder := gomatrixserverlib.EventBuilder{
|
||||||
Sender: userID,
|
Sender: userID,
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
Type: "m.room.member",
|
Type: "m.room.member",
|
||||||
StateKey: &userID,
|
StateKey: &userID,
|
||||||
}
|
}
|
||||||
err := builder.SetContent(map[string]interface{}{"membership": "join"})
|
err = builder.SetContent(map[string]interface{}{"membership": "join"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return httputil.LogThenError(httpReq, err)
|
return httputil.LogThenError(httpReq, err)
|
||||||
}
|
}
|
||||||
|
|
@ -86,6 +101,7 @@ func SendJoin(
|
||||||
request *gomatrixserverlib.FederationRequest,
|
request *gomatrixserverlib.FederationRequest,
|
||||||
cfg config.Dendrite,
|
cfg config.Dendrite,
|
||||||
query api.RoomserverQueryAPI,
|
query api.RoomserverQueryAPI,
|
||||||
|
producer *producers.RoomserverProducer,
|
||||||
now time.Time,
|
now time.Time,
|
||||||
keys gomatrixserverlib.KeyRing,
|
keys gomatrixserverlib.KeyRing,
|
||||||
roomID, eventID string,
|
roomID, eventID string,
|
||||||
|
|
@ -139,13 +155,27 @@ func SendJoin(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Fetch state and auth events
|
var stateAndAuthChainRepsonse api.QueryStateAndAuthChainResponse
|
||||||
|
err = query.QueryStateAndAuthChain(ctx, &api.QueryStateAndAuthChainRequest{
|
||||||
|
PrevEventIDs: event.PrevEventIDs(),
|
||||||
|
RoomID: roomID,
|
||||||
|
}, &stateAndAuthChainRepsonse)
|
||||||
|
if err != nil {
|
||||||
|
return httputil.LogThenError(httpReq, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// We are responsible for notifying other servers that the user has joined
|
||||||
|
// the room
|
||||||
|
err = producer.SendEvents(ctx, []gomatrixserverlib.Event{event}, cfg.Matrix.ServerName)
|
||||||
|
if err != nil {
|
||||||
|
return httputil.LogThenError(httpReq, err)
|
||||||
|
}
|
||||||
|
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: 200,
|
Code: 200,
|
||||||
JSON: map[string]interface{}{
|
JSON: map[string]interface{}{
|
||||||
"state": []gomatrixserverlib.Event{},
|
"state": stateAndAuthChainRepsonse.StateEvents,
|
||||||
"auth_chain": []gomatrixserverlib.Event{},
|
"auth_chain": stateAndAuthChainRepsonse.AuthChainEvents,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -142,8 +142,8 @@ func Setup(
|
||||||
vars := mux.Vars(httpReq)
|
vars := mux.Vars(httpReq)
|
||||||
roomID := vars["roomID"]
|
roomID := vars["roomID"]
|
||||||
userID := vars["userID"]
|
userID := vars["userID"]
|
||||||
return MakeJoin(
|
return SendJoin(
|
||||||
httpReq.Context(), httpReq, request, cfg, query, time.Now(), keys, roomID, userID,
|
httpReq.Context(), httpReq, request, cfg, query, producer, time.Now(), keys, roomID, userID,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)).Methods("PUT")
|
)).Methods("PUT")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue