Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! Fix clear DB when logout in web
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Oct 2, 2023
1 parent 18e4cb2 commit a69bb0b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
14 changes: 7 additions & 7 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Client extends MatrixApi {

final Duration sendTimelineEventTimeout;

bool _supportDeleteCache = false;
bool _supportDeleteCollections = false;

Future<MatrixImageFileResizedResponse?> Function(
MatrixImageFileResizeArguments)? customImageResizer;
Expand Down Expand Up @@ -1035,7 +1035,7 @@ class Client extends MatrixApi {
await abortSync();
await dispose(closeDatabase: false);

final export = await database!.exportDump(supportDeleteCache: _supportDeleteCache);
final export = await database!.exportDump(supportDeleteCollections: _supportDeleteCollections);

await clear();
return export;
Expand All @@ -1056,7 +1056,7 @@ class Client extends MatrixApi {

_database ??= await databaseBuilder!.call(this);

final success = await database!.importDump(export, supportDeleteCache: _supportDeleteCache);
final success = await database!.importDump(export, supportDeleteCollections: _supportDeleteCollections);

if (success) {
// closing including DB
Expand Down Expand Up @@ -1590,7 +1590,7 @@ class Client extends MatrixApi {
Logs().outputEvents.clear();
try {
await abortSync();
await database?.clear(supportDeleteCache: _supportDeleteCache);
await database?.clear(supportDeleteCollections: _supportDeleteCollections);
_backgroundSync = true;
} catch (e, s) {
Logs().e('Unable to clear database', e, s);
Expand Down Expand Up @@ -3055,7 +3055,7 @@ class Client extends MatrixApi {
Logs().e('Unable to migrate inbound group sessions!', e, s);
}

await legacyDatabase.clear(supportDeleteCache: _supportDeleteCache);
await legacyDatabase.clear(supportDeleteCollections: _supportDeleteCollections);
}
await legacyDatabase?.close();
_initLock = false;
Expand All @@ -3067,8 +3067,8 @@ class Client extends MatrixApi {
}
}

set isSupportDeleteCache(bool supportDeleteCache) {
_supportDeleteCache = supportDeleteCache;
set issupportDeleteCollections(bool supportDeleteCollections) {
_supportDeleteCollections = supportDeleteCollections;
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/database/database_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ abstract class DatabaseApi {
Future<void> clearCache();

Future<void> clear({
bool supportDeleteCache = false,
bool supportDeleteCollections = false,
});

Future<User?> getUser(String userId, Room room);
Expand Down Expand Up @@ -311,10 +311,10 @@ abstract class DatabaseApi {

Future<void> transaction(Future<void> Function() action);

Future<String> exportDump({bool supportDeleteCache = false});
Future<String> exportDump({bool supportDeleteCollections = false});

Future<bool> importDump(
String export, {
bool supportDeleteCache = false,
bool supportDeleteCollections = false,
});
}
12 changes: 6 additions & 6 deletions lib/src/database/hive_collections_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class HiveCollectionsDatabase extends DatabaseApi {

@override
Future<void> clear({
bool supportDeleteCache = false,
bool supportDeleteCollections = false,
}) =>
transaction(() async {
await _clientBox.clear();
Expand All @@ -265,7 +265,7 @@ class HiveCollectionsDatabase extends DatabaseApi {
await _eventsBox.clear();
await _seenDeviceIdsBox.clear();
await _seenDeviceKeysBox.clear();
if (!supportDeleteCache) {
if (supportDeleteCollections) {
await _collection.deleteFromDisk();
}
});
Expand Down Expand Up @@ -1491,7 +1491,7 @@ class HiveCollectionsDatabase extends DatabaseApi {
}

@override
Future<String> exportDump({bool supportDeleteCache = false}) async {
Future<String> exportDump({bool supportDeleteCollections = false}) async {
final dataMap = {
_clientBoxName: await _clientBox.getAllValues(),
_accountDataBoxName: await _accountDataBox.getAllValues(),
Expand All @@ -1518,17 +1518,17 @@ class HiveCollectionsDatabase extends DatabaseApi {
_seenDeviceKeysBoxName: await _seenDeviceKeysBox.getAllValues(),
};
final json = jsonEncode(dataMap);
await clear(supportDeleteCache: supportDeleteCache);
await clear(supportDeleteCollections: supportDeleteCollections);
return json;
}

@override
Future<bool> importDump(
String export, {
bool supportDeleteCache = false,
bool supportDeleteCollections = false,
}) async {
try {
await clear(supportDeleteCache: supportDeleteCache);
await clear(supportDeleteCollections: supportDeleteCollections);
await open();
final json = Map.from(jsonDecode(export)).cast<String, Map>();
for (final key in json[_clientBoxName]!.keys) {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/database/hive_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {

@override
Future<void> clear({
bool supportDeleteCache = false,
bool supportDeleteCollections = false,
}) async {
Logs().i('Clear and close hive database...');
await _actionOnAllBoxes((box) async {
Expand Down Expand Up @@ -1453,15 +1453,15 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
}

@override
Future<String> exportDump({bool supportDeleteCache = false}) {
Future<String> exportDump({bool supportDeleteCollections = false}) {
// see no need to implement this in a deprecated part
throw UnimplementedError();
}

@override
Future<bool> importDump(
String export, {
bool supportDeleteCache = false,
bool supportDeleteCollections = false,
}) {
// see no need to implement this in a deprecated part
throw UnimplementedError();
Expand Down

0 comments on commit a69bb0b

Please sign in to comment.