From 2a33b17ee18e25d7a6b986d260fc49f01b84c1b8 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Tue, 14 Feb 2017 17:21:55 +0000 Subject: [PATCH] Add IsStateEvent utility method for checking if EventStateKeyNID is 0 --- src/github.com/matrix-org/dendrite/roomserver/input/state.go | 2 +- src/github.com/matrix-org/dendrite/roomserver/types/types.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/github.com/matrix-org/dendrite/roomserver/input/state.go b/src/github.com/matrix-org/dendrite/roomserver/input/state.go index 24edaed49..e76406ba5 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/input/state.go +++ b/src/github.com/matrix-org/dendrite/roomserver/input/state.go @@ -124,7 +124,7 @@ func calculateAndStoreStateMany(db RoomEventDatabase, roomNID types.RoomNID, pre } fullState = append(fullState, entries...) } - if prevState.EventStateKeyNID != 0 { + if prevState.IsStateEvent() { // If the prev event was a state event then add an entry for the event itself // so that we get the state after the event rather than the state before. fullState = append(fullState, prevState.StateEntry) diff --git a/src/github.com/matrix-org/dendrite/roomserver/types/types.go b/src/github.com/matrix-org/dendrite/roomserver/types/types.go index 6ce714eab..000238495 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/types/types.go +++ b/src/github.com/matrix-org/dendrite/roomserver/types/types.go @@ -74,6 +74,11 @@ type StateAtEvent struct { StateEntry } +// IsStateEvent returns whether the event the state is at is a state event. +func (s StateAtEvent) IsStateEvent() bool { + return s.EventStateKeyNID != 0 +} + // An Event is a gomatrixserverlib.Event with the numeric event ID attached. // It is when performing bulk event lookup in the database. type Event struct {