Various roominfo tweaks (#2607)

This commit is contained in:
Neil Alexander 2022-08-02 12:27:15 +01:00 committed by GitHub
parent eab87ef07d
commit ca3fa58388
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 16 deletions

View file

@ -217,6 +217,14 @@ func (u *RoomUpdater) SetLatestEvents(
roomNID types.RoomNID, latest []types.StateAtEventAndReference, lastEventNIDSent types.EventNID,
currentStateSnapshotNID types.StateSnapshotNID,
) error {
switch {
case len(latest) == 0:
return fmt.Errorf("cannot set latest events with no latest event references")
case currentStateSnapshotNID == 0:
return fmt.Errorf("cannot set latest events with invalid state snapshot NID")
case lastEventNIDSent == 0:
return fmt.Errorf("cannot set latest events with invalid latest event NID")
}
eventNIDs := make([]types.EventNID, len(latest))
for i := range latest {
eventNIDs[i] = latest[i].EventNID
@ -229,8 +237,10 @@ func (u *RoomUpdater) SetLatestEvents(
// Since it's entirely possible that this types.RoomInfo came from the
// cache, we should make sure to update that entry so that the next run
// works from live data.
u.roomInfo.SetStateSnapshotNID(currentStateSnapshotNID)
u.roomInfo.SetIsStub(false)
if u.roomInfo != nil {
u.roomInfo.SetStateSnapshotNID(currentStateSnapshotNID)
u.roomInfo.SetIsStub(false)
}
return nil
})
}