aboutsummaryrefslogtreecommitdiff
path: root/appservice
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-04-06 16:10:31 +0100
committerGitHub <noreply@github.com>2022-04-06 16:10:31 +0100
commit99f2007eb6ad75ce8e19b3c3088f552034a1644d (patch)
tree28eabb99268221e11488b0c334ba2ffb67d24adf /appservice
parent850932c7a735c896184f30cd7e26a9a0a0f73b3b (diff)
Fix bug where state events could be requested twice in appservices (#2328)
* Fix bug where state events could be requested twice (should fix #2305) * Avoid a pointless HTTP request if possible
Diffstat (limited to 'appservice')
-rw-r--r--appservice/consumers/roomserver.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/appservice/consumers/roomserver.go b/appservice/consumers/roomserver.go
index 01790722..31e05caa 100644
--- a/appservice/consumers/roomserver.go
+++ b/appservice/consumers/roomserver.go
@@ -83,20 +83,29 @@ func (s *OutputRoomEventConsumer) onMessage(ctx context.Context, msg *nats.Msg)
return true
}
- if output.Type != api.OutputTypeNewRoomEvent {
+ if output.Type != api.OutputTypeNewRoomEvent || output.NewRoomEvent == nil {
return true
}
- events := []*gomatrixserverlib.HeaderedEvent{output.NewRoomEvent.Event}
+ newEventID := output.NewRoomEvent.Event.EventID()
+ events := make([]*gomatrixserverlib.HeaderedEvent, 0, len(output.NewRoomEvent.AddsStateEventIDs))
+ events = append(events, output.NewRoomEvent.Event)
if len(output.NewRoomEvent.AddsStateEventIDs) > 0 {
eventsReq := &api.QueryEventsByIDRequest{
- EventIDs: output.NewRoomEvent.AddsStateEventIDs,
+ EventIDs: make([]string, 0, len(output.NewRoomEvent.AddsStateEventIDs)),
}
eventsRes := &api.QueryEventsByIDResponse{}
- if err := s.rsAPI.QueryEventsByID(s.ctx, eventsReq, eventsRes); err != nil {
- return false
+ for _, eventID := range output.NewRoomEvent.AddsStateEventIDs {
+ if eventID != newEventID {
+ eventsReq.EventIDs = append(eventsReq.EventIDs, eventID)
+ }
+ }
+ if len(eventsReq.EventIDs) > 0 {
+ if err := s.rsAPI.QueryEventsByID(s.ctx, eventsReq, eventsRes); err != nil {
+ return false
+ }
+ events = append(events, eventsRes.Events...)
}
- events = append(events, eventsRes.Events...)
}
// Send event to any relevant application services