From 82062d9b53a2e2d51c9ae37ae8d4b49ca6b0c81c Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 9 Sep 2020 17:51:01 +0100 Subject: [PATCH] Improve outlier check --- roomserver/api/wrapper.go | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/roomserver/api/wrapper.go b/roomserver/api/wrapper.go index 6be2cce9d..e37462aff 100644 --- a/roomserver/api/wrapper.go +++ b/roomserver/api/wrapper.go @@ -67,27 +67,36 @@ func SendEventWithState( if haveEventIDs[authOrStateEvent.EventID()] { continue } - if _, ok := isCurrentState[authOrStateEvent.EventID()]; !ok { - // If this is an auth event rather than a current state event - // then store it as an outlier. We won't include it in the - // current state set for the input event. + + // Work out whether we should store the event as an outlier + // or if we should send it as a rewrite event. + storeAsOutlier := false + if authOrStateEvent.Type() == event.Type() && *authOrStateEvent.StateKey() == *event.StateKey() { + // The event is the same as the event that we are looking + // to send as a new event. + storeAsOutlier = true + } else if _, ok := isCurrentState[authOrStateEvent.EventID()]; !ok { + // The event doesn't belong to the current state but is + // actually an auth event. + storeAsOutlier = true + } + + if storeAsOutlier { ires = append(ires, InputRoomEvent{ Kind: KindOutlier, Event: authOrStateEvent.Headered(event.RoomVersion), AuthEventIDs: authOrStateEvent.AuthEventIDs(), }) - continue + } else { + ires = append(ires, InputRoomEvent{ + Kind: KindRewrite, + Event: authOrStateEvent.Headered(event.RoomVersion), + AuthEventIDs: authOrStateEvent.AuthEventIDs(), + HasState: true, + StateEventIDs: stateIDs, + }) + stateIDs = append(stateIDs, authOrStateEvent.EventID()) } - // The event is a current state event. Send it as a rewrite - // event so that we generate a state output event for it. - ires = append(ires, InputRoomEvent{ - Kind: KindRewrite, - Event: authOrStateEvent.Headered(event.RoomVersion), - AuthEventIDs: authOrStateEvent.AuthEventIDs(), - HasState: true, - StateEventIDs: stateIDs, - }) - stateIDs = append(stateIDs, authOrStateEvent.EventID()) } // Send the final event as a new event, which will generate