From 710752060addae80fd1704428def55602ad4945d Mon Sep 17 00:00:00 2001 From: Krille Date: Tue, 28 Mar 2023 14:28:42 +0200 Subject: [PATCH] feat: Implement onMigration callback to Client.init() method --- lib/src/client.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 3d457be9..8859e5bb 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -1386,6 +1386,9 @@ class Client extends MatrixApi { String? newOlmAccount, bool waitForFirstSync = true, bool waitUntilLoadCompletedLoaded = true, + + /// Will be called if the app performs a migration task from the [legacyDatabaseBuilder] + void Function()? onMigration, }) async { if ((newToken != null || newUserID != null || @@ -1450,7 +1453,7 @@ class Client extends MatrixApi { if (accessToken == null || homeserver == null || userID == null) { if (legacyDatabaseBuilder != null) { - await _migrateFromLegacyDatabase(); + await _migrateFromLegacyDatabase(onMigration: onMigration); if (isLogged()) return; } // we aren't logged in @@ -2912,7 +2915,9 @@ class Client extends MatrixApi { return; } - Future _migrateFromLegacyDatabase() async { + Future _migrateFromLegacyDatabase({ + void Function()? onMigration, + }) async { Logs().i('Check legacy database for migration data...'); final legacyDatabase = await legacyDatabaseBuilder?.call(this); final migrateClient = await legacyDatabase?.getClient(clientName); @@ -2920,6 +2925,7 @@ class Client extends MatrixApi { if (migrateClient != null && legacyDatabase != null && database != null) { Logs().i('Found data in the legacy database!'); + onMigration?.call(); _id = migrateClient['client_id']; await database.insertClient( clientName,