Skip to content

Commit

Permalink
Ensure NID slices are never nil
Browse files Browse the repository at this point in the history
Otherwise we have to get the storage functions to convert this to a
nonnil slice before we insert in the DB.
  • Loading branch information
David Robertson committed Jul 12, 2023
1 parent 5e378cb commit 93779be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions state/accumulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ func TestCalculateNewSnapshotDupe(t *testing.T) {
Type: "a",
StateKey: "b",
},
wantOtherNIDs: []int64{2},
wantOtherNIDs: []int64{2},
wantMemberNIDs: []int64{},
},
// basic addition
{
Expand All @@ -479,7 +480,8 @@ func TestCalculateNewSnapshotDupe(t *testing.T) {
Type: "c",
StateKey: "d",
},
wantOtherNIDs: []int64{1, 2},
wantOtherNIDs: []int64{1, 2},
wantMemberNIDs: []int64{},
},
// dupe nid
{
Expand Down
5 changes: 5 additions & 0 deletions state/event_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ func (ev *Event) ensureFieldsSetOnEvent() error {

type StrippedEvents []Event

// NIDs partitions the nids in this set of stripped events into the nids of membership
// events and all others. The returned lists inherit their order from the given slice of
// StrippedEvents, and are never nil.
func (se StrippedEvents) NIDs() (membershipNIDs, otherNIDs []int64) {
membershipNIDs = make([]int64, 0, len(se))
otherNIDs = make([]int64, 0, len(se))
for _, s := range se {
if s.Type == "m.room.member" {
membershipNIDs = append(membershipNIDs, s.NID)
Expand Down

0 comments on commit 93779be

Please sign in to comment.