diff --git a/federationapi/routing/invite.go b/federationapi/routing/invite.go index 7241173ec..48527aa45 100644 --- a/federationapi/routing/invite.go +++ b/federationapi/routing/invite.go @@ -37,10 +37,12 @@ func Invite( producer *producers.RoomserverProducer, keys gomatrixserverlib.KeyRing, ) util.JSONResponse { + fmt.Println("Receiving invite:", string(request.Content())) + var intermediate struct { - Event json.RawMessage `json:"event"` - InviteRoomState []gomatrixserverlib.InviteV2StrippedState `json:"invite_room_state"` - RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"` + Event json.RawMessage `json:"event"` + InviteRoomState []json.RawMessage `json:"invite_stripped_state"` + RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"` } // Unmarshal the request into the intermediate form. @@ -111,11 +113,21 @@ func Invite( string(cfg.Matrix.ServerName), cfg.Matrix.KeyID, cfg.Matrix.PrivateKey, ) + // Try parsing invite states one by one. This allows us to drop only the invite + // states that are invalid rather than dropping all of them in one go. + inviteStates := []gomatrixserverlib.InviteV2StrippedState{} + for _, isj := range intermediate.InviteRoomState { + var inviteState gomatrixserverlib.InviteV2StrippedState + if err = json.Unmarshal(isj, &inviteState); err == nil { + inviteStates = append(inviteStates, inviteState) + } + } + // Add the invite event to the roomserver. if err = producer.SendInvite( httpReq.Context(), signedEvent.Headered(intermediate.RoomVersion), - intermediate.InviteRoomState, + inviteStates, ); err != nil { util.GetLogger(httpReq.Context()).WithError(err).Error("producer.SendInvite failed") return jsonerror.InternalServerError() diff --git a/syncapi/storage/postgres/syncserver.go b/syncapi/storage/postgres/syncserver.go index 1e078ef46..e610fc2ce 100644 --- a/syncapi/storage/postgres/syncserver.go +++ b/syncapi/storage/postgres/syncserver.go @@ -449,11 +449,6 @@ func (d *SyncServerDatasource) addPDUDeltaToResponse( } } - // TODO: This should be done in getStateDeltas - if err = d.addInvitesToResponse(ctx, txn, device.UserID, fromPos, toPos, res); err != nil { - return nil, err - } - succeeded = true return joinedRoomIDs, nil } diff --git a/syncapi/sync/requestpool.go b/syncapi/sync/requestpool.go index 69efd8aa8..4f03ac3f6 100644 --- a/syncapi/sync/requestpool.go +++ b/syncapi/sync/requestpool.go @@ -69,6 +69,7 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype logger.WithError(err).Error("rp.currentSyncForUser failed") return jsonerror.InternalServerError() } + logger.WithField("next", syncData.NextBatch).Info("Responding immediately") return util.JSONResponse{ Code: http.StatusOK,