bridgev2/legacymigrate: add post-migrate hook
Some checks failed
Go / Lint (latest) (push) Has been cancelled
Go / Build (old, libolm) (push) Has been cancelled
Go / Build (latest, libolm) (push) Has been cancelled
Go / Build (old, goolm) (push) Has been cancelled
Go / Build (latest, goolm) (push) Has been cancelled

Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
Sumner Evans 2025-04-02 09:10:35 -06:00
commit 74a02366d7
No known key found for this signature in database
2 changed files with 15 additions and 4 deletions

View file

@ -226,11 +226,18 @@ func (br *BridgeMain) PostMigrate(ctx context.Context) error {
Object("portal_key", portal.PortalKey).
Str("room_type", string(portal.RoomType)).
Msg("Migrating portal")
switch portal.RoomType {
case database.RoomTypeDM:
err = br.postMigrateDMPortal(ctx, portal)
if br.PostMigratePortal != nil {
err = br.PostMigratePortal(ctx, portal)
if err != nil {
return fmt.Errorf("failed to update DM portal %s: %w", portal.MXID, err)
return fmt.Errorf("failed to run post-migrate portal hook for %s: %w", portal.MXID, err)
}
} else {
switch portal.RoomType {
case database.RoomTypeDM:
err = br.postMigrateDMPortal(ctx, portal)
if err != nil {
return fmt.Errorf("failed to update DM portal %s: %w", portal.MXID, err)
}
}
}
_, err = br.Matrix.Bot.SendStateEvent(ctx, portal.MXID, event.StateElementFunctionalMembers, "", &event.ElementFunctionalMembersContent{

View file

@ -67,6 +67,10 @@ type BridgeMain struct {
PostInit func()
PostStart func()
// PostMigratePortal is a function that will be called during a legacy
// migration for each portal.
PostMigratePortal func(context.Context, *bridgev2.Portal) error
// Connector is the network connector for the bridge.
Connector bridgev2.NetworkConnector