fix api.SendEventWithState with no event

This commit is contained in:
Matthew Hodgson 2020-09-13 03:32:01 +01:00
parent a160c074e8
commit 32f898d668
3 changed files with 9 additions and 5 deletions

View file

@ -459,7 +459,7 @@ func (t *txnReq) processEventWithMissingState(ctx context.Context, e gomatrixser
// pass the event along with the state to the roomserver using a background context so we don't
// needlessly expire
headeredEvent := e.Headered(roomVersion)
return api.SendEventWithState(context.Background(), t.rsAPI, resolvedState, &headeredEvent, t.haveEventIDs())
return api.SendEventWithState(context.Background(), t.rsAPI, resolvedState, &headeredEvent, t.haveEventIDs(), roomVersion)
}
// lookupStateAfterEvent returns the room state after `eventID`, which is the state before eventID with the state of `eventID` (if it's a state event)

View file

@ -201,6 +201,7 @@ func (r *FederationSenderInternalAPI) performJoinUsingServer(
respState,
&headeredEvent,
nil,
respMakeJoin.RoomVersion,
); err != nil {
return fmt.Errorf("r.producer.SendEventWithState: %w", err)
}
@ -310,7 +311,7 @@ func (r *FederationSenderInternalAPI) performOutboundPeekUsingServer(
}
}
// Try to perform a /peek using the information supplied in the
// Try to perform an outbound /peek using the information supplied in the
// request.
respPeek, err := r.federation.Peek(
ctx,
@ -321,12 +322,12 @@ func (r *FederationSenderInternalAPI) performOutboundPeekUsingServer(
)
if err != nil {
r.statistics.ForServer(serverName).Failure()
return fmt.Errorf("r.federation.MakePeek: %w", err)
return fmt.Errorf("r.federation.Peek: %w", err)
}
r.statistics.ForServer(serverName).Success()
// Work out if we support the room version that has been supplied in
// the make_peek response.
// the peek response.
if respPeek.RoomVersion == "" {
respPeek.RoomVersion = gomatrixserverlib.RoomVersionV1
}
@ -349,11 +350,13 @@ func (r *FederationSenderInternalAPI) performOutboundPeekUsingServer(
}
respState := respPeek.ToRespState()
// logrus.Warnf("converted respPeek %#v to respState %#v", respPeek, respState)
// Send the newly returned state to the roomserver to update our local view.
if err = roomserverAPI.SendEventWithState(
ctx, r.rsAPI,
&respState,
nil, nil,
respPeek.RoomVersion,
); err != nil {
return fmt.Errorf("r.producer.SendEventWithState: %w", err)
}

View file

@ -47,6 +47,7 @@ func SendEvents(
func SendEventWithState(
ctx context.Context, rsAPI RoomserverInternalAPI, state *gomatrixserverlib.RespState,
event *gomatrixserverlib.HeaderedEvent, haveEventIDs map[string]bool,
roomVersion gomatrixserverlib.RoomVersion,
) error {
outliers, err := state.Events()
if err != nil {
@ -60,7 +61,7 @@ func SendEventWithState(
}
ires = append(ires, InputRoomEvent{
Kind: KindOutlier,
Event: outlier.Headered(event.RoomVersion),
Event: outlier.Headered(roomVersion),
AuthEventIDs: outlier.AuthEventIDs(),
})
}