mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
Handle remote room upgrades (#2866)
Makes the following tests pass ``` /upgrade moves remote aliases to the new room Local and remote users' homeservers remove a room from their public directory on upgrade ```
This commit is contained in:
parent
858a4af224
commit
2a77a910eb
4 changed files with 50 additions and 1 deletions
|
@ -172,4 +172,5 @@ type Database interface {
|
|||
ForgetRoom(ctx context.Context, userID, roomID string, forget bool) error
|
||||
|
||||
GetHistoryVisibilityState(ctx context.Context, roomInfo *types.RoomInfo, eventID string, domain string) ([]*gomatrixserverlib.Event, error)
|
||||
UpgradeRoom(ctx context.Context, oldRoomID, newRoomID, eventSender string) error
|
||||
}
|
||||
|
|
|
@ -1408,6 +1408,36 @@ func (d *Database) ForgetRoom(ctx context.Context, userID, roomID string, forget
|
|||
})
|
||||
}
|
||||
|
||||
func (d *Database) UpgradeRoom(ctx context.Context, oldRoomID, newRoomID, eventSender string) error {
|
||||
|
||||
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||
// un-publish old room
|
||||
if err := d.PublishedTable.UpsertRoomPublished(ctx, txn, oldRoomID, "", "", false); err != nil {
|
||||
return fmt.Errorf("failed to unpublish room: %w", err)
|
||||
}
|
||||
// publish new room
|
||||
if err := d.PublishedTable.UpsertRoomPublished(ctx, txn, newRoomID, "", "", true); err != nil {
|
||||
return fmt.Errorf("failed to publish room: %w", err)
|
||||
}
|
||||
|
||||
// Migrate any existing room aliases
|
||||
aliases, err := d.RoomAliasesTable.SelectAliasesFromRoomID(ctx, txn, oldRoomID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get room aliases: %w", err)
|
||||
}
|
||||
|
||||
for _, alias := range aliases {
|
||||
if err = d.RoomAliasesTable.DeleteRoomAlias(ctx, txn, alias); err != nil {
|
||||
return fmt.Errorf("failed to remove room alias: %w", err)
|
||||
}
|
||||
if err = d.RoomAliasesTable.InsertRoomAlias(ctx, txn, alias, newRoomID, eventSender); err != nil {
|
||||
return fmt.Errorf("failed to set room alias: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// FIXME TODO: Remove all this - horrible dupe with roomserver/state. Can't use the original impl because of circular loops
|
||||
// it should live in this package!
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue