mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
Don't send adds_state_events
in roomserver output events anymore (#2258)
* Don't send `adds_state_events` in roomserver output events anymore * Set `omitempty` on some output fields that aren't always set * Add `AddsState` helper function * No-op if no added state event IDs * Revert "No-op if no added state event IDs" This reverts commit 71a0ef3df10e0d94234d916246c30b0a4e82b26e. * Revert "Add `AddsState` helper function" This reverts commit c9fbe45475eb12ae44d2a8da7c0fc3a002ad9819.
This commit is contained in:
parent
05fa66c9c8
commit
67de4dbd0c
5 changed files with 79 additions and 80 deletions
|
@ -154,7 +154,42 @@ func (s *OutputRoomEventConsumer) onNewRoomEvent(
|
|||
ctx context.Context, msg api.OutputNewRoomEvent,
|
||||
) error {
|
||||
ev := msg.Event
|
||||
addsStateEvents := msg.AddsState()
|
||||
|
||||
addsStateEvents := []*gomatrixserverlib.HeaderedEvent{}
|
||||
foundEventIDs := map[string]bool{}
|
||||
if len(msg.AddsStateEventIDs) > 0 {
|
||||
for _, eventID := range msg.AddsStateEventIDs {
|
||||
foundEventIDs[eventID] = false
|
||||
}
|
||||
foundEvents, err := s.db.Events(ctx, msg.AddsStateEventIDs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("s.db.Events: %w", err)
|
||||
}
|
||||
for _, event := range foundEvents {
|
||||
foundEventIDs[event.EventID()] = true
|
||||
}
|
||||
eventsReq := &api.QueryEventsByIDRequest{}
|
||||
eventsRes := &api.QueryEventsByIDResponse{}
|
||||
for eventID, found := range foundEventIDs {
|
||||
if !found {
|
||||
eventsReq.EventIDs = append(eventsReq.EventIDs, eventID)
|
||||
}
|
||||
}
|
||||
if err = s.rsAPI.QueryEventsByID(ctx, eventsReq, eventsRes); err != nil {
|
||||
return fmt.Errorf("s.rsAPI.QueryEventsByID: %w", err)
|
||||
}
|
||||
for _, event := range eventsRes.Events {
|
||||
eventID := event.EventID()
|
||||
foundEvents = append(foundEvents, event)
|
||||
foundEventIDs[eventID] = true
|
||||
}
|
||||
for eventID, found := range foundEventIDs {
|
||||
if !found {
|
||||
return fmt.Errorf("event %s is missing", eventID)
|
||||
}
|
||||
}
|
||||
addsStateEvents = foundEvents
|
||||
}
|
||||
|
||||
ev, err := s.updateStateEvent(ev)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue