Merge branch 'main' of github.com:matrix-org/dendrite into s7evink/syncunreadcount

This commit is contained in:
Till Faelligen 2022-09-16 12:00:13 +02:00
commit 65ffbc3d9a
No known key found for this signature in database
GPG key ID: 3DF82D8AB9211D4E

View file

@ -264,16 +264,27 @@ func (u *latestEventsUpdater) latestState() error {
return fmt.Errorf("roomState.CalculateAndStoreStateAfterEvents: %w", err) return fmt.Errorf("roomState.CalculateAndStoreStateAfterEvents: %w", err)
} }
// Now that we have a new state snapshot based on the latest events, // Include information about what changed in the state transition. If the
// we can compare that new snapshot to the previous one and see what // event rewrites the state (i.e. is a federated join) then we will simply
// has changed. This gives us one list of removed state events and // include the entire state snapshot as added events, as the "RewritesState"
// another list of added ones. Replacing a value for a state-key tuple // flag in the output event signals downstream components to purge their
// will result one removed (the old event) and one added (the new event). // room state first. If it doesn't rewrite the state then we will work out
u.removed, u.added, err = roomState.DifferenceBetweeenStateSnapshots( // what the difference is between the state snapshots and send that. In all
ctx, u.oldStateNID, u.newStateNID, // cases where a state event is being replaced, the old state event will
) // appear in "removed" and the replacement will appear in "added".
if err != nil { if u.rewritesState {
return fmt.Errorf("roomState.DifferenceBetweenStateSnapshots: %w", err) u.removed = []types.StateEntry{}
u.added, err = roomState.LoadStateAtSnapshot(ctx, u.newStateNID)
if err != nil {
return fmt.Errorf("roomState.LoadStateAtSnapshot: %w", err)
}
} else {
u.removed, u.added, err = roomState.DifferenceBetweeenStateSnapshots(
ctx, u.oldStateNID, u.newStateNID,
)
if err != nil {
return fmt.Errorf("roomState.DifferenceBetweenStateSnapshots: %w", err)
}
} }
if removed := len(u.removed) - len(u.added); !u.rewritesState && removed > 0 { if removed := len(u.removed) - len(u.added); !u.rewritesState && removed > 0 {