mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 07:28:27 +00:00
Use "event"
field from RespSendJoin
This commit is contained in:
parent
046a6331bd
commit
1e3c19f31d
2 changed files with 9 additions and 47 deletions
|
@ -571,31 +571,6 @@ func SendJoin(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since we performed QueryStateAndAuthChain before we sent the membership event to the
|
|
||||||
// roomserver, we need to ensure that the stateAndAuthChainResponse contain the new join
|
|
||||||
// event. It would be expensive to call QueryStateAndAuthChain again, so we'll just modify
|
|
||||||
// the response in situ.
|
|
||||||
replaced := false
|
|
||||||
for i := range stateAndAuthChainResponse.StateEvents {
|
|
||||||
stateEvent := stateAndAuthChainResponse.StateEvents[i]
|
|
||||||
if event.Type() != gomatrixserverlib.MRoomMember {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if stateEvent.StateKeyEquals(*event.StateKey()) {
|
|
||||||
stateAndAuthChainResponse.StateEvents[i] = event.Headered(
|
|
||||||
stateAndAuthChainResponse.RoomVersion,
|
|
||||||
)
|
|
||||||
replaced = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !replaced {
|
|
||||||
stateAndAuthChainResponse.StateEvents = append(
|
|
||||||
stateAndAuthChainResponse.StateEvents,
|
|
||||||
event.Headered(stateAndAuthChainResponse.RoomVersion),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// sort events deterministically by depth (lower is earlier)
|
// sort events deterministically by depth (lower is earlier)
|
||||||
// We also do this because sytest's basic federation server isn't good at using the correct
|
// We also do this because sytest's basic federation server isn't good at using the correct
|
||||||
// state if these lists are randomised, resulting in flakey tests. :(
|
// state if these lists are randomised, resulting in flakey tests. :(
|
||||||
|
@ -606,6 +581,7 @@ func SendJoin(
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
JSON: gomatrixserverlib.RespSendJoin{
|
JSON: gomatrixserverlib.RespSendJoin{
|
||||||
|
Event: event,
|
||||||
StateEvents: gomatrixserverlib.UnwrapEventHeaders(stateAndAuthChainResponse.StateEvents),
|
StateEvents: gomatrixserverlib.UnwrapEventHeaders(stateAndAuthChainResponse.StateEvents),
|
||||||
AuthEvents: gomatrixserverlib.UnwrapEventHeaders(stateAndAuthChainResponse.AuthChainEvents),
|
AuthEvents: gomatrixserverlib.UnwrapEventHeaders(stateAndAuthChainResponse.AuthChainEvents),
|
||||||
Origin: cfg.Matrix.ServerName,
|
Origin: cfg.Matrix.ServerName,
|
||||||
|
|
|
@ -247,6 +247,13 @@ func (r *FederationSenderInternalAPI) performJoinUsingServer(
|
||||||
defer close(waiterr)
|
defer close(waiterr)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
// If the remote server returned a signed membership event then
|
||||||
|
// we will use that instead. That is necessary for restricted
|
||||||
|
// joins to work.
|
||||||
|
if respSendJoin.Event != nil {
|
||||||
|
event = respSendJoin.Event
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Can we expand Check here to return a list of missing auth
|
// TODO: Can we expand Check here to return a list of missing auth
|
||||||
// events rather than failing one at a time?
|
// events rather than failing one at a time?
|
||||||
respState, err := respSendJoin.Check(ctx, r.keyRing, event, federatedAuthProvider(ctx, r.federation, r.keyRing, serverName))
|
respState, err := respSendJoin.Check(ctx, r.keyRing, event, federatedAuthProvider(ctx, r.federation, r.keyRing, serverName))
|
||||||
|
@ -259,27 +266,6 @@ func (r *FederationSenderInternalAPI) performJoinUsingServer(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the membership event.
|
|
||||||
var joinEvent *gomatrixserverlib.Event
|
|
||||||
for _, stateEvent := range respState.StateEvents {
|
|
||||||
if stateEvent.Type() != gomatrixserverlib.MRoomMember {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if stateEvent.StateKeyEquals(*event.StateKey()) {
|
|
||||||
joinEvent = event
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if joinEvent == nil {
|
|
||||||
err = fmt.Errorf("The remote server did not send back our join event")
|
|
||||||
logrus.WithFields(logrus.Fields{
|
|
||||||
"room_id": roomID,
|
|
||||||
"user_id": userID,
|
|
||||||
}).WithError(err).Error("Found no membership event")
|
|
||||||
waiterr <- err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we successfully performed a send_join above then the other
|
// If we successfully performed a send_join above then the other
|
||||||
// server now thinks we're a part of the room. Send the newly
|
// server now thinks we're a part of the room. Send the newly
|
||||||
// returned state to the roomserver to update our local view.
|
// returned state to the roomserver to update our local view.
|
||||||
|
@ -287,7 +273,7 @@ func (r *FederationSenderInternalAPI) performJoinUsingServer(
|
||||||
ctx, r.rsAPI,
|
ctx, r.rsAPI,
|
||||||
roomserverAPI.KindNew,
|
roomserverAPI.KindNew,
|
||||||
respState,
|
respState,
|
||||||
joinEvent.Headered(respMakeJoin.RoomVersion),
|
event.Headered(respMakeJoin.RoomVersion),
|
||||||
nil,
|
nil,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
|
|
Loading…
Reference in a new issue