Skip to content

Commit

Permalink
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 115bf9e commit 986dd74
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 42 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 _kIsWeb = false;
bool _supportDeleteCache = 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(isWeb: _kIsWeb);
final export = await database!.exportDump(isWeb: _supportDeleteCache);

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, isWeb: _kIsWeb);
final success = await database!.importDump(export, isWeb: _supportDeleteCache);

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(isWeb: _kIsWeb);
await database?.clear(isWeb: _supportDeleteCache);
_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(isWeb: _kIsWeb);
await legacyDatabase.clear(isWeb: _supportDeleteCache);
}
await legacyDatabase?.close();
_initLock = false;
Expand All @@ -3067,8 +3067,8 @@ class Client extends MatrixApi {
}
}

set isSupportPlatformWeb(bool kIsWeb) {
_kIsWeb = kIsWeb;
set isSupportDeleteCache(bool kIsWeb) {
_supportDeleteCache = kIsWeb;
}
}

Expand Down
71 changes: 36 additions & 35 deletions lib/src/database/hive_collections_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -244,43 +244,44 @@ class HiveCollectionsDatabase extends DatabaseApi {
@override
Future<void> clear({
bool isWeb = false,
}) async {
await _clientBox.clear();
await _accountDataBox.clear();
await _roomsBox.clear();
await _roomStateBox.clear();
await _roomMembersBox.clear();
await _toDeviceQueueBox.clear();
await _roomAccountDataBox.clear();
await _inboundGroupSessionsBox.clear();
await _outboundGroupSessionsBox.clear();
await _olmSessionsBox.clear();
await _userDeviceKeysBox.clear();
await _userDeviceKeysOutdatedBox.clear();
await _userCrossSigningKeysBox.clear();
await _ssssCacheBox.clear();
await _presencesBox.clear();
await _timelineFragmentsBox.clear();
await _eventsBox.clear();
await _seenDeviceIdsBox.clear();
await _seenDeviceKeysBox.clear();
if (!isWeb) {
await _collection.deleteFromDisk();
}
}
}) =>
transaction(() async {
await _clientBox.clear();
await _accountDataBox.clear();
await _roomsBox.clear();
await _roomStateBox.clear();
await _roomMembersBox.clear();
await _toDeviceQueueBox.clear();
await _roomAccountDataBox.clear();
await _inboundGroupSessionsBox.clear();
await _outboundGroupSessionsBox.clear();
await _olmSessionsBox.clear();
await _userDeviceKeysBox.clear();
await _userDeviceKeysOutdatedBox.clear();
await _userCrossSigningKeysBox.clear();
await _ssssCacheBox.clear();
await _presencesBox.clear();
await _timelineFragmentsBox.clear();
await _eventsBox.clear();
await _seenDeviceIdsBox.clear();
await _seenDeviceKeysBox.clear();
if (!isWeb) {
await _collection.deleteFromDisk();
}
});

@override
Future<void> clearCache() async {
await _roomsBox.clear();
await _accountDataBox.clear();
await _roomStateBox.clear();
await _roomMembersBox.clear();
await _eventsBox.clear();
await _timelineFragmentsBox.clear();
await _outboundGroupSessionsBox.clear();
await _presencesBox.clear();
await _clientBox.delete('prev_batch');
}
Future<void> clearCache() => transaction(() async {
await _roomsBox.clear();
await _accountDataBox.clear();
await _roomStateBox.clear();
await _roomMembersBox.clear();
await _eventsBox.clear();
await _timelineFragmentsBox.clear();
await _outboundGroupSessionsBox.clear();
await _presencesBox.clear();
await _clientBox.delete('prev_batch');
});

@override
Future<void> clearSSSSCache() => _ssssCacheBox.clear();
Expand Down

0 comments on commit 986dd74

Please sign in to comment.