Fix auth_events, prev_events

This commit is contained in:
Neil Alexander 2020-04-01 10:41:52 +01:00
parent 942b2db448
commit 68fc39cb6a

View file

@ -108,29 +108,23 @@ func AddPrevEventsToEvent(
// The limits here feel a bit arbitrary but they are currently here // The limits here feel a bit arbitrary but they are currently here
// because of https://github.com/matrix-org/matrix-doc/issues/2307 // because of https://github.com/matrix-org/matrix-doc/issues/2307
// and because Synapse will just drop events that don't comply. // and because Synapse will just drop events that don't comply.
truncAuthEvents, truncPrevEvents := refs, queryRes.LatestEvents
if len(truncAuthEvents) > 10 {
truncAuthEvents = truncAuthEvents[:10]
}
if len(truncPrevEvents) > 20 {
truncPrevEvents = truncPrevEvents[:20]
}
switch eventFormat { switch eventFormat {
case gomatrixserverlib.EventFormatV1: case gomatrixserverlib.EventFormatV1:
builder.AuthEvents = refs builder.AuthEvents = truncAuthEvents
builder.PrevEvents = queryRes.LatestEvents builder.PrevEvents = truncPrevEvents
if len(builder.AuthEvents) > 10 {
builder.AuthEvents = builder.AuthEvents[:10]
}
if len(builder.PrevEvents) > 20 {
builder.PrevEvents = builder.PrevEvents[:20]
}
case gomatrixserverlib.EventFormatV2: case gomatrixserverlib.EventFormatV2:
v2AuthRefs := []string{} v2AuthRefs, v2PrevRefs := []string{}, []string{}
v2PrevRefs := []string{} for _, ref := range truncAuthEvents {
for _, ref := range refs {
if len(v2AuthRefs) == 10 {
break
}
v2AuthRefs = append(v2AuthRefs, ref.EventID) v2AuthRefs = append(v2AuthRefs, ref.EventID)
} }
for _, ref := range queryRes.LatestEvents { for _, ref := range truncPrevEvents {
if len(v2PrevRefs) == 20 {
break
}
v2PrevRefs = append(v2PrevRefs, ref.EventID) v2PrevRefs = append(v2PrevRefs, ref.EventID)
} }
builder.AuthEvents = v2AuthRefs builder.AuthEvents = v2AuthRefs