aboutsummaryrefslogtreecommitdiff
path: root/roomserver/internal/input_events.go
diff options
context:
space:
mode:
Diffstat (limited to 'roomserver/internal/input_events.go')
-rw-r--r--roomserver/internal/input_events.go24
1 files changed, 16 insertions, 8 deletions
diff --git a/roomserver/internal/input_events.go b/roomserver/internal/input_events.go
index a6308299..287db1af 100644
--- a/roomserver/internal/input_events.go
+++ b/roomserver/internal/input_events.go
@@ -64,7 +64,7 @@ func (r *RoomserverInternalAPI) processRoomEvent(
}
// Store the event.
- roomNID, stateAtEvent, redactionEvent, redactedEventID, err := r.DB.StoreEvent(ctx, event, input.TransactionID, authEventNIDs)
+ _, stateAtEvent, redactionEvent, redactedEventID, err := r.DB.StoreEvent(ctx, event, input.TransactionID, authEventNIDs)
if err != nil {
return "", fmt.Errorf("r.DB.StoreEvent: %w", err)
}
@@ -89,10 +89,18 @@ func (r *RoomserverInternalAPI) processRoomEvent(
return event.EventID(), nil
}
+ roomInfo, err := r.DB.RoomInfo(ctx, event.RoomID())
+ if err != nil {
+ return "", fmt.Errorf("r.DB.RoomInfo: %w", err)
+ }
+ if roomInfo == nil {
+ return "", fmt.Errorf("r.DB.RoomInfo missing for room %s", event.RoomID())
+ }
+
if stateAtEvent.BeforeStateSnapshotNID == 0 {
// We haven't calculated a state for this event yet.
// Lets calculate one.
- err = r.calculateAndSetState(ctx, input, roomNID, &stateAtEvent, event)
+ err = r.calculateAndSetState(ctx, input, *roomInfo, &stateAtEvent, event)
if err != nil {
return "", fmt.Errorf("r.calculateAndSetState: %w", err)
}
@@ -100,7 +108,7 @@ func (r *RoomserverInternalAPI) processRoomEvent(
if err = r.updateLatestEvents(
ctx, // context
- roomNID, // room NID to update
+ roomInfo, // room info for the room being updated
stateAtEvent, // state at event (below)
event, // event
input.SendAsServer, // send as server
@@ -135,19 +143,19 @@ func (r *RoomserverInternalAPI) processRoomEvent(
func (r *RoomserverInternalAPI) calculateAndSetState(
ctx context.Context,
input api.InputRoomEvent,
- roomNID types.RoomNID,
+ roomInfo types.RoomInfo,
stateAtEvent *types.StateAtEvent,
event gomatrixserverlib.Event,
) error {
var err error
- roomState := state.NewStateResolution(r.DB)
+ roomState := state.NewStateResolution(r.DB, roomInfo)
if input.HasState {
// Check here if we think we're in the room already.
stateAtEvent.Overwrite = true
var joinEventNIDs []types.EventNID
// Request join memberships only for local users only.
- if joinEventNIDs, err = r.DB.GetMembershipEventNIDsForRoom(ctx, roomNID, true, true); err == nil {
+ if joinEventNIDs, err = r.DB.GetMembershipEventNIDsForRoom(ctx, roomInfo.RoomNID, true, true); err == nil {
// If we have no local users that are joined to the room then any state about
// the room that we have is quite possibly out of date. Therefore in that case
// we should overwrite it rather than merge it.
@@ -161,14 +169,14 @@ func (r *RoomserverInternalAPI) calculateAndSetState(
return err
}
- if stateAtEvent.BeforeStateSnapshotNID, err = r.DB.AddState(ctx, roomNID, nil, entries); err != nil {
+ if stateAtEvent.BeforeStateSnapshotNID, err = r.DB.AddState(ctx, roomInfo.RoomNID, nil, entries); err != nil {
return err
}
} else {
stateAtEvent.Overwrite = false
// We haven't been told what the state at the event is so we need to calculate it from the prev_events
- if stateAtEvent.BeforeStateSnapshotNID, err = roomState.CalculateAndStoreStateBeforeEvent(ctx, event, roomNID); err != nil {
+ if stateAtEvent.BeforeStateSnapshotNID, err = roomState.CalculateAndStoreStateBeforeEvent(ctx, event); err != nil {
return err
}
}