From 71a0ef3df10e0d94234d916246c30b0a4e82b26e Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 7 Mar 2022 16:38:24 +0000 Subject: [PATCH] No-op if no added state event IDs --- roomserver/api/output.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/roomserver/api/output.go b/roomserver/api/output.go index edc2251ce..4a6f54595 100644 --- a/roomserver/api/output.go +++ b/roomserver/api/output.go @@ -170,14 +170,16 @@ type OutputNewRoomEvent struct { // The slice returned contains the output room event itself in all cases. func (o *OutputNewRoomEvent) AddsState(ctx context.Context, rsAPI RoomserverInternalAPI) ([]*gomatrixserverlib.HeaderedEvent, error) { events := make([]*gomatrixserverlib.HeaderedEvent, 0, len(o.AddsStateEventIDs)) - eventsReq := &QueryEventsByIDRequest{ - EventIDs: o.AddsStateEventIDs, + if len(o.AddsStateEventIDs) > 0 { + eventsReq := &QueryEventsByIDRequest{ + EventIDs: o.AddsStateEventIDs, + } + eventsRes := &QueryEventsByIDResponse{} + if err := rsAPI.QueryEventsByID(ctx, eventsReq, eventsRes); err != nil { + return nil, fmt.Errorf("s.rsAPI.QueryEventsByID: %w", err) + } + events = append(events, eventsRes.Events...) } - eventsRes := &QueryEventsByIDResponse{} - if err := rsAPI.QueryEventsByID(ctx, eventsReq, eventsRes); err != nil { - return nil, fmt.Errorf("s.rsAPI.QueryEventsByID: %w", err) - } - events = append(events, eventsRes.Events...) return events, nil }