support SendEventWithState with optional event

This commit is contained in:
Matthew Hodgson 2020-09-11 22:31:32 +01:00
parent 4ef6a3c759
commit 65e59a1af9

View file

@ -42,10 +42,11 @@ func SendEvents(
// SendEventWithState writes an event with KindNew to the roomserver // SendEventWithState writes an event with KindNew to the roomserver
// with the state at the event as KindOutlier before it. Will not send any event that is // with the state at the event as KindOutlier before it. Will not send any event that is
// marked as `true` in haveEventIDs // marked as `true` in haveEventIDs. The event itself is optional in case
// hou just want to write outliers to the roomserver.
func SendEventWithState( func SendEventWithState(
ctx context.Context, rsAPI RoomserverInternalAPI, state *gomatrixserverlib.RespState, ctx context.Context, rsAPI RoomserverInternalAPI, state *gomatrixserverlib.RespState,
event gomatrixserverlib.HeaderedEvent, haveEventIDs map[string]bool, event *gomatrixserverlib.HeaderedEvent, haveEventIDs map[string]bool,
) error { ) error {
outliers, err := state.Events() outliers, err := state.Events()
if err != nil { if err != nil {
@ -69,13 +70,15 @@ func SendEventWithState(
stateEventIDs[i] = state.StateEvents[i].EventID() stateEventIDs[i] = state.StateEvents[i].EventID()
} }
ires = append(ires, InputRoomEvent{ if event != nil {
Kind: KindNew, ires = append(ires, InputRoomEvent{
Event: event, Kind: KindNew,
AuthEventIDs: event.AuthEventIDs(), Event: *event,
HasState: true, AuthEventIDs: event.AuthEventIDs(),
StateEventIDs: stateEventIDs, HasState: true,
}) StateEventIDs: stateEventIDs,
})
}
return SendInputRoomEvents(ctx, rsAPI, ires) return SendInputRoomEvents(ctx, rsAPI, ires)
} }