Prevent duplicate events from being sent...

* Strip event content if it doesn't contain anything

Signed-off-by: Andrew Morgan <andrewm@matrix.org>
This commit is contained in:
Andrew Morgan 2018-06-14 16:29:46 +01:00
parent 17273aa547
commit 945c48eb47
3 changed files with 13 additions and 3 deletions

View file

@ -50,7 +50,7 @@ func SetupAppServiceAPIComponent(
// a sync.Cond object that can be used to notify workers when there are new // a sync.Cond object that can be used to notify workers when there are new
// events to be sent out. // events to be sent out.
workerStates := make([]types.ApplicationServiceWorkerState, len(base.Cfg.Derived.ApplicationServices)) workerStates := make([]types.ApplicationServiceWorkerState, len(base.Cfg.Derived.ApplicationServices))
for _, appservice := range base.Cfg.Derived.ApplicationServices { for i, appservice := range base.Cfg.Derived.ApplicationServices {
eventCount := 0 eventCount := 0
m := sync.Mutex{} m := sync.Mutex{}
@ -59,7 +59,7 @@ func SetupAppServiceAPIComponent(
Cond: sync.NewCond(&m), Cond: sync.NewCond(&m),
EventsReady: &eventCount, EventsReady: &eventCount,
} }
workerStates = append(workerStates, ws) workerStates[i] = ws
} }
consumer := consumers.NewOutputRoomEventConsumer( consumer := consumers.NewOutputRoomEventConsumer(

View file

@ -116,6 +116,10 @@ func (s *OutputRoomEventConsumer) onMessage(msg *sarama.ConsumerMessage) error {
} }
// Check if any events need to passed on to external application services // Check if any events need to passed on to external application services
if len(events) > 0 {
// Check if this was a membership event
return s.filterRoomserverEvents(ctx, events)
}
return s.filterRoomserverEvents(ctx, append(events, ev)) return s.filterRoomserverEvents(ctx, append(events, ev))
} }

View file

@ -210,6 +210,12 @@ func (s *eventsStatements) insertEvent(
appServiceID string, appServiceID string,
event *gomatrixserverlib.Event, event *gomatrixserverlib.Event,
) (err error) { ) (err error) {
// If event has no content, strip the json
content := event.Content()
if string(content) == "{\"disable\":true}" {
content = []byte("{}")
}
_, err = s.insertEventStmt.ExecContext( _, err = s.insertEventStmt.ExecContext(
ctx, ctx,
appServiceID, appServiceID,
@ -218,7 +224,7 @@ func (s *eventsStatements) insertEvent(
event.RoomID(), event.RoomID(),
event.Type(), event.Type(),
event.Sender(), event.Sender(),
event.Content(), content,
-1, // No transaction ID yet -1, // No transaction ID yet
) )
return return