Tidy up that create check further

This commit is contained in:
Neil Alexander 2022-02-09 12:02:51 +00:00
parent 42e995792d
commit c5c4381f3d
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
2 changed files with 5 additions and 1 deletions

View file

@ -150,7 +150,7 @@ func (r *Queryer) QueryMissingAuthPrevEvents(
for _, prevEventID := range request.PrevEventIDs {
state, err := r.DB.StateAtEventIDs(ctx, []string{prevEventID})
if err != nil || len(state) == 0 || ((state[0].EventTypeNID != types.MRoomCreateNID || state[0].EventStateKeyNID != types.EmptyStateKeyNID) && state[0].BeforeStateSnapshotNID == 0) {
if err != nil || len(state) == 0 || (!state[0].IsCreate() && state[0].BeforeStateSnapshotNID == 0) {
response.MissingPrevEventIDs = append(response.MissingPrevEventIDs, prevEventID)
}
}

View file

@ -83,6 +83,10 @@ type StateKeyTuple struct {
EventStateKeyNID EventStateKeyNID
}
func (a StateKeyTuple) IsCreate() bool {
return a.EventTypeNID == MRoomCreateNID && a.EventStateKeyNID == EmptyStateKeyNID
}
// LessThan returns true if this state key is less than the other state key.
// The ordering is arbitrary and is used to implement binary search and to efficiently deduplicate entries.
func (a StateKeyTuple) LessThan(b StateKeyTuple) bool {