mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-23 14:53:10 -06:00
Rename to PurgeRoom
This commit is contained in:
parent
ae998c17e2
commit
a571989495
|
|
@ -145,15 +145,8 @@ func (s *OutputRoomEventConsumer) onNewRoomEvent(
|
|||
}
|
||||
|
||||
if msg.RewritesState {
|
||||
err = s.db.RewriteState(
|
||||
ctx,
|
||||
&ev,
|
||||
addsStateEvents,
|
||||
msg.AddsStateEventIDs,
|
||||
msg.TransactionID,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("s.db.RewriteState: %w", err)
|
||||
if err = s.db.PurgeRoom(ctx, ev.RoomID()); err != nil {
|
||||
return fmt.Errorf("s.db.PurgeRoom: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,9 +41,9 @@ type Database interface {
|
|||
// Returns an error if there was a problem inserting this event.
|
||||
WriteEvent(ctx context.Context, ev *gomatrixserverlib.HeaderedEvent, addStateEvents []gomatrixserverlib.HeaderedEvent,
|
||||
addStateEventIDs []string, removeStateEventIDs []string, transactionID *api.TransactionID, excludeFromSync bool) (types.StreamPosition, error)
|
||||
// RewriteState rewrites a current room state event. If the state event is a create event then all existing
|
||||
// state in the room will be deleted before rewriting the event.
|
||||
RewriteState(ctx context.Context, ev *gomatrixserverlib.HeaderedEvent, addStateEvents []gomatrixserverlib.HeaderedEvent, addStateEventIDs []string, transactionID *api.TransactionID) error
|
||||
// PurgeRoom completely purges room state from the sync API. This is done when
|
||||
// receiving an output event that completely resets the state.
|
||||
PurgeRoom(ctx context.Context, roomID string) error
|
||||
// GetStateEvent returns the Matrix state event of a given type for a given room with a given state key
|
||||
// If no event could be found, returns nil
|
||||
// If there was an issue during the retrieval, returns an error
|
||||
|
|
|
|||
|
|
@ -241,39 +241,25 @@ func (d *Database) handleBackwardExtremities(ctx context.Context, txn *sql.Tx, e
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *Database) RewriteState(
|
||||
ctx context.Context,
|
||||
ev *gomatrixserverlib.HeaderedEvent,
|
||||
addStateEvents []gomatrixserverlib.HeaderedEvent,
|
||||
addStateEventIDs []string,
|
||||
transactionID *api.TransactionID,
|
||||
func (d *Database) PurgeRoom(
|
||||
ctx context.Context, roomID string,
|
||||
) error {
|
||||
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||
// If the event is a create event then we'll delete all of the existing
|
||||
// data for the room. The only reason that a create event would be replayed
|
||||
// to us in this way is if we're about to receive the entire room state.
|
||||
if ev.Type() == gomatrixserverlib.MRoomCreate {
|
||||
if err := d.CurrentRoomState.DeleteRoomStateForRoom(ctx, txn, ev.RoomID()); err != nil {
|
||||
return fmt.Errorf("d.CurrentRoomState.DeleteRoomStateForRoom: %w", err)
|
||||
}
|
||||
if err := d.OutputEvents.DeleteEventsForRoom(ctx, txn, ev.RoomID()); err != nil {
|
||||
return fmt.Errorf("d.Events.DeleteEventsForRoom: %w", err)
|
||||
}
|
||||
if err := d.Topology.DeleteTopologyForRoom(ctx, txn, ev.RoomID()); err != nil {
|
||||
return fmt.Errorf("d.Topology.DeleteTopologyForRoom: %w", err)
|
||||
}
|
||||
if err := d.BackwardExtremities.DeleteBackwardExtremitiesForRoom(ctx, txn, ev.RoomID()); err != nil {
|
||||
return fmt.Errorf("d.BackwardExtremities.DeleteBackwardExtremitiesForRoom: %w", err)
|
||||
}
|
||||
if err := d.CurrentRoomState.DeleteRoomStateForRoom(ctx, txn, roomID); err != nil {
|
||||
return fmt.Errorf("d.CurrentRoomState.DeleteRoomStateForRoom: %w", err)
|
||||
}
|
||||
if err := d.OutputEvents.DeleteEventsForRoom(ctx, txn, roomID); err != nil {
|
||||
return fmt.Errorf("d.Events.DeleteEventsForRoom: %w", err)
|
||||
}
|
||||
if err := d.Topology.DeleteTopologyForRoom(ctx, txn, roomID); err != nil {
|
||||
return fmt.Errorf("d.Topology.DeleteTopologyForRoom: %w", err)
|
||||
}
|
||||
if err := d.BackwardExtremities.DeleteBackwardExtremitiesForRoom(ctx, txn, roomID); err != nil {
|
||||
return fmt.Errorf("d.BackwardExtremities.DeleteBackwardExtremitiesForRoom: %w", err)
|
||||
}
|
||||
|
||||
/*
|
||||
if err := d.handleBackwardExtremities(ctx, txn, ev); err != nil {
|
||||
return fmt.Errorf("d.handleBackwardExtremities: %w", err)
|
||||
}
|
||||
*/
|
||||
// TODO: is there something better here that we can do instead of giving stream position 0?
|
||||
//return d.updateRoomState(ctx, txn, []string{}, addStateEvents, types.StreamPosition(0))
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue