aboutsummaryrefslogtreecommitdiff
path: root/clientapi/routing/createroom.go
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2020-08-17 17:33:19 +0100
committerGitHub <noreply@github.com>2020-08-17 17:33:19 +0100
commita5a85c6a11f7ab6f1ab4c1d83e2ca1cf781b03b8 (patch)
treec0f12ad7104fc89d21cc7bbd94d88f3f7086b49b /clientapi/routing/createroom.go
parente7d450adb8c81c7e9e7d314206bb9b141718a31a (diff)
Make PerformJoin responsible for sending invite to RS input (#1277)
* Make PerformJoin send input membership event * Invite input room events in separate goroutine * Don't limit roomserver input events using request context * Synchronous input room events * Nope, that didn't work * oops send state key to GetMembership * Don't generate stripped state in client API more times than necessary, generate output events on receiving end of federated invite * Commit membership updater changes * Tweaks
Diffstat (limited to 'clientapi/routing/createroom.go')
-rw-r--r--clientapi/routing/createroom.go75
1 files changed, 42 insertions, 33 deletions
diff --git a/clientapi/routing/createroom.go b/clientapi/routing/createroom.go
index 36837d40..57fc3f33 100644
--- a/clientapi/routing/createroom.go
+++ b/clientapi/routing/createroom.go
@@ -371,20 +371,10 @@ func createRoom(
}
// If this is a direct message then we should invite the participants.
- for _, invitee := range r.Invite {
- // Build the invite event.
- inviteEvent, err := buildMembershipEvent(
- req.Context(), invitee, "", accountDB, device, gomatrixserverlib.Invite,
- roomID, true, cfg, evTime, rsAPI, asAPI,
- )
- if err != nil {
- util.GetLogger(req.Context()).WithError(err).Error("buildMembershipEvent failed")
- continue
- }
+ if len(r.Invite) > 0 {
// Build some stripped state for the invite.
- candidates := append(gomatrixserverlib.UnwrapEventHeaders(builtEvents), inviteEvent.Event)
- var strippedState []gomatrixserverlib.InviteV2StrippedState
- for _, event := range candidates {
+ var globalStrippedState []gomatrixserverlib.InviteV2StrippedState
+ for _, event := range builtEvents {
switch event.Type() {
case gomatrixserverlib.MRoomName:
fallthrough
@@ -395,29 +385,48 @@ func createRoom(
case gomatrixserverlib.MRoomMember:
fallthrough
case gomatrixserverlib.MRoomJoinRules:
- strippedState = append(
- strippedState,
- gomatrixserverlib.NewInviteV2StrippedState(&event),
+ ev := event.Event
+ globalStrippedState = append(
+ globalStrippedState,
+ gomatrixserverlib.NewInviteV2StrippedState(&ev),
)
}
}
- // Send the invite event to the roomserver.
- err = roomserverAPI.SendInvite(
- req.Context(), rsAPI,
- inviteEvent.Headered(roomVersion),
- strippedState, // invite room state
- cfg.Matrix.ServerName, // send as server
- nil, // transaction ID
- )
- switch e := err.(type) {
- case *roomserverAPI.PerformError:
- return e.JSONResponse()
- case nil:
- default:
- util.GetLogger(req.Context()).WithError(err).Error("roomserverAPI.SendInvite failed")
- return util.JSONResponse{
- Code: http.StatusInternalServerError,
- JSON: jsonerror.InternalServerError(),
+
+ // Process the invites.
+ for _, invitee := range r.Invite {
+ // Build the invite event.
+ inviteEvent, err := buildMembershipEvent(
+ req.Context(), invitee, "", accountDB, device, gomatrixserverlib.Invite,
+ roomID, true, cfg, evTime, rsAPI, asAPI,
+ )
+ if err != nil {
+ util.GetLogger(req.Context()).WithError(err).Error("buildMembershipEvent failed")
+ continue
+ }
+ inviteStrippedState := append(
+ globalStrippedState,
+ gomatrixserverlib.NewInviteV2StrippedState(&inviteEvent.Event),
+ )
+ // Send the invite event to the roomserver.
+ err = roomserverAPI.SendInvite(
+ req.Context(),
+ rsAPI,
+ inviteEvent.Headered(roomVersion),
+ inviteStrippedState, // invite room state
+ cfg.Matrix.ServerName, // send as server
+ nil, // transaction ID
+ )
+ switch e := err.(type) {
+ case *roomserverAPI.PerformError:
+ return e.JSONResponse()
+ case nil:
+ default:
+ util.GetLogger(req.Context()).WithError(err).Error("roomserverAPI.SendInvite failed")
+ return util.JSONResponse{
+ Code: http.StatusInternalServerError,
+ JSON: jsonerror.InternalServerError(),
+ }
}
}
}