From 53c474f93ed112c73a969dd0220dd76fb065325d Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Thu, 23 Nov 2023 19:33:08 +0100 Subject: [PATCH] Move makeOutputNewRoomEvent --- .../internal/input/input_latest_events.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/roomserver/internal/input/input_latest_events.go b/roomserver/internal/input/input_latest_events.go index dd0bd6049..cd3ff7e0e 100644 --- a/roomserver/internal/input/input_latest_events.go +++ b/roomserver/internal/input/input_latest_events.go @@ -89,6 +89,12 @@ func (r *Inputer) updateLatestEvents( return fmt.Errorf("u.doUpdateLatestEvents: %w", err) } + update, err := u.makeOutputNewRoomEvent() + if err != nil { + return fmt.Errorf("u.makeOutputNewRoomEvent: %w", err) + } + updates = append(updates, *update) + // Send the event to the output logs. // We do this inside the database transaction to ensure that we only mark an event as sent if we sent it. // (n.b. this means that it's possible that the same event will be sent twice if the transaction fails but @@ -184,7 +190,7 @@ func (u *latestEventsUpdater) doUpdateLatestEvents() ([]api.OutputEvent, error) // Now that we know what the latest events are, it's time to get the // latest state. - var updates []api.OutputEvent + var membershipUpdates []api.OutputEvent if extremitiesChanged || u.rewritesState { if err = u.latestState(); err != nil { return nil, fmt.Errorf("u.latestState: %w", err) @@ -192,7 +198,7 @@ func (u *latestEventsUpdater) doUpdateLatestEvents() ([]api.OutputEvent, error) // If we need to generate any output events then here's where we do it. // TODO: Move this! - if updates, err = u.api.updateMemberships(u.ctx, u.updater, u.removed, u.added); err != nil { + if membershipUpdates, err = u.api.updateMemberships(u.ctx, u.updater, u.removed, u.added); err != nil { return nil, fmt.Errorf("u.api.updateMemberships: %w", err) } } else { @@ -203,13 +209,7 @@ func (u *latestEventsUpdater) doUpdateLatestEvents() ([]api.OutputEvent, error) return nil, fmt.Errorf("u.updater.SetLatestEvents: %w", err) } - update, err := u.makeOutputNewRoomEvent() - if err != nil { - return nil, fmt.Errorf("u.makeOutputNewRoomEvent: %w", err) - } - updates = append(updates, *update) - - return updates, nil + return membershipUpdates, nil } func (u *latestEventsUpdater) latestState() error {