mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-16 03:13:11 -06:00
Refactor out calculateAndSetState to decrease cyclomatic complexity
This commit is contained in:
parent
93a6178d45
commit
0919a5c109
|
|
@ -105,6 +105,30 @@ func processRoomEvent(
|
||||||
if stateAtEvent.BeforeStateSnapshotNID == 0 {
|
if stateAtEvent.BeforeStateSnapshotNID == 0 {
|
||||||
// We haven't calculated a state for this event yet.
|
// We haven't calculated a state for this event yet.
|
||||||
// Lets calculate one.
|
// Lets calculate one.
|
||||||
|
err = calculateAndSetState(ctx, db, input, roomNID, &stateAtEvent, event)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if input.Kind == api.KindBackfill {
|
||||||
|
// Backfill is not implemented.
|
||||||
|
panic("Not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the extremities of the event graph for the room
|
||||||
|
return updateLatestEvents(ctx, db, ow, roomNID, stateAtEvent, event, input.SendAsServer, input.TransactionID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func calculateAndSetState(
|
||||||
|
ctx context.Context,
|
||||||
|
db RoomEventDatabase,
|
||||||
|
input api.InputRoomEvent,
|
||||||
|
roomNID types.RoomNID,
|
||||||
|
stateAtEvent *types.StateAtEvent,
|
||||||
|
event gomatrixserverlib.Event,
|
||||||
|
) error {
|
||||||
|
var err error
|
||||||
if input.HasState {
|
if input.HasState {
|
||||||
// We've been told what the state at the event is so we don't need to calculate it.
|
// We've been told what the state at the event is so we don't need to calculate it.
|
||||||
// Check that those state events are in the database and store the state.
|
// Check that those state events are in the database and store the state.
|
||||||
|
|
@ -122,19 +146,7 @@ func processRoomEvent(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = db.SetState(ctx, stateAtEvent.EventNID, stateAtEvent.BeforeStateSnapshotNID)
|
return db.SetState(ctx, stateAtEvent.EventNID, stateAtEvent.BeforeStateSnapshotNID)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if input.Kind == api.KindBackfill {
|
|
||||||
// Backfill is not implemented.
|
|
||||||
panic("Not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the extremities of the event graph for the room
|
|
||||||
return updateLatestEvents(ctx, db, ow, roomNID, stateAtEvent, event, input.SendAsServer, input.TransactionID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func processInviteEvent(
|
func processInviteEvent(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue