From c5c4381f3d9ec3624b37daba2a1fc1d51282863c Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 9 Feb 2022 12:02:51 +0000 Subject: [PATCH] Tidy up that create check further --- roomserver/internal/query/query.go | 2 +- roomserver/types/types.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/roomserver/internal/query/query.go b/roomserver/internal/query/query.go index 1c3a770f2..05cd686f4 100644 --- a/roomserver/internal/query/query.go +++ b/roomserver/internal/query/query.go @@ -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) } } diff --git a/roomserver/types/types.go b/roomserver/types/types.go index 5e1eebe98..5d52ccfcd 100644 --- a/roomserver/types/types.go +++ b/roomserver/types/types.go @@ -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 {