Handle invite in appservice roomserver consumer (#2476)

Signed-off-by: Aaron Ogle <aaron@geekgonecrazy.com>
This commit is contained in:
Aaron Ogle 2022-05-24 03:07:33 -05:00 committed by GitHub
parent 4472267901
commit 20844942a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,29 +83,38 @@ func (s *OutputRoomEventConsumer) onMessage(ctx context.Context, msg *nats.Msg)
return true return true
} }
if output.Type != api.OutputTypeNewRoomEvent || output.NewRoomEvent == nil { log.WithFields(log.Fields{
return true "type": output.Type,
} }).Debug("Got a message in OutputRoomEventConsumer")
newEventID := output.NewRoomEvent.Event.EventID() events := []*gomatrixserverlib.HeaderedEvent{}
events := make([]*gomatrixserverlib.HeaderedEvent, 0, len(output.NewRoomEvent.AddsStateEventIDs)) if output.Type == api.OutputTypeNewRoomEvent && output.NewRoomEvent != nil {
events = append(events, output.NewRoomEvent.Event) newEventID := output.NewRoomEvent.Event.EventID()
if len(output.NewRoomEvent.AddsStateEventIDs) > 0 { events = append(events, output.NewRoomEvent.Event)
eventsReq := &api.QueryEventsByIDRequest{ if len(output.NewRoomEvent.AddsStateEventIDs) > 0 {
EventIDs: make([]string, 0, len(output.NewRoomEvent.AddsStateEventIDs)), eventsReq := &api.QueryEventsByIDRequest{
} EventIDs: make([]string, 0, len(output.NewRoomEvent.AddsStateEventIDs)),
eventsRes := &api.QueryEventsByIDResponse{} }
for _, eventID := range output.NewRoomEvent.AddsStateEventIDs { eventsRes := &api.QueryEventsByIDResponse{}
if eventID != newEventID { for _, eventID := range output.NewRoomEvent.AddsStateEventIDs {
eventsReq.EventIDs = append(eventsReq.EventIDs, eventID) 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...)
} }
} }
if len(eventsReq.EventIDs) > 0 { } else if output.Type == api.OutputTypeNewInviteEvent && output.NewInviteEvent != nil {
if err := s.rsAPI.QueryEventsByID(s.ctx, eventsReq, eventsRes); err != nil { events = append(events, output.NewInviteEvent.Event)
return false } else {
} log.WithFields(log.Fields{
events = append(events, eventsRes.Events...) "type": output.Type,
} }).Debug("appservice OutputRoomEventConsumer ignoring event", string(msg.Data))
return true
} }
// Send event to any relevant application services // Send event to any relevant application services