From 16dae954787106726d7ec0e58717b4e5bd373260 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 25 Oct 2017 18:18:47 +0100 Subject: [PATCH] Wire up producers --- .../dendrite/federationapi/routing/join.go | 38 +++++++++++++++++-- .../dendrite/federationapi/routing/routing.go | 4 +- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/federationapi/routing/join.go b/src/github.com/matrix-org/dendrite/federationapi/routing/join.go index 99e8d82de..b9b7196e3 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/routing/join.go +++ b/src/github.com/matrix-org/dendrite/federationapi/routing/join.go @@ -22,6 +22,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/httputil" "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/config" "github.com/matrix-org/dendrite/roomserver/api" @@ -39,13 +40,27 @@ func MakeJoin( keys gomatrixserverlib.KeyRing, roomID, userID string, ) 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{ Sender: userID, RoomID: roomID, Type: "m.room.member", StateKey: &userID, } - err := builder.SetContent(map[string]interface{}{"membership": "join"}) + err = builder.SetContent(map[string]interface{}{"membership": "join"}) if err != nil { return httputil.LogThenError(httpReq, err) } @@ -86,6 +101,7 @@ func SendJoin( request *gomatrixserverlib.FederationRequest, cfg config.Dendrite, query api.RoomserverQueryAPI, + producer *producers.RoomserverProducer, now time.Time, keys gomatrixserverlib.KeyRing, 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{ Code: 200, JSON: map[string]interface{}{ - "state": []gomatrixserverlib.Event{}, - "auth_chain": []gomatrixserverlib.Event{}, + "state": stateAndAuthChainRepsonse.StateEvents, + "auth_chain": stateAndAuthChainRepsonse.AuthChainEvents, }, } } diff --git a/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go b/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go index 4f2ff4e52..0122800f5 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go @@ -142,8 +142,8 @@ func Setup( vars := mux.Vars(httpReq) roomID := vars["roomID"] userID := vars["userID"] - return MakeJoin( - httpReq.Context(), httpReq, request, cfg, query, time.Now(), keys, roomID, userID, + return SendJoin( + httpReq.Context(), httpReq, request, cfg, query, producer, time.Now(), keys, roomID, userID, ) }, )).Methods("PUT")