Skip to content

Commit

Permalink
fix: clean tom db on logout
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian KOUNE authored and hoangdat committed Sep 7, 2023
1 parent 93b616f commit 696bfd4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 5 additions & 4 deletions lib/data/hive/hive_collection_tom_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ class HiveCollectionToMDatabase {
try {
await db.open();
} catch (e, s) {
Logs().w('Unable to open Hive. Delete database and storage key...', e, s);
const FlutterSecureStorage()
.delete(key: FlutterHiveCollectionsDatabase.cipherStorageKey);
Logs().w('Unable to open Hive.', e, s);
await db.clear().catchError((_) {});
await Hive.deleteFromDisk();
rethrow;
}
Logs().d('Hive for ToM is ready');
Expand Down Expand Up @@ -123,6 +120,10 @@ class HiveCollectionToMDatabase {
}

Future<void> clear() async {
Logs().w('Delete database and storage key...');
await const FlutterSecureStorage()
.delete(key: FlutterHiveCollectionsDatabase.cipherStorageKey);
await tomConfigurationsBox.clear();
await Hive.deleteFromDisk();
}
}
10 changes: 6 additions & 4 deletions lib/widgets/matrix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:io';
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:collection/collection.dart';
import 'package:desktop_notifications/desktop_notifications.dart';
import 'package:fluffychat/data/hive/hive_collection_tom_database.dart';
import 'package:fluffychat/data/network/interceptor/authorization_interceptor.dart';
import 'package:fluffychat/data/network/interceptor/dynamic_url_interceptor.dart';
import 'package:fluffychat/di/global/get_it_initializer.dart';
Expand Down Expand Up @@ -341,7 +342,8 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
hidPopup = true;
await KeyVerificationDialog(request: request).show(navigatorContext!);
});
onLoginStateChanged[name] ??= c.onLoginStateChanged.stream.listen((state) {
onLoginStateChanged[name] ??=
c.onLoginStateChanged.stream.listen((state) async {
final loggedInWithMultipleClients = widget.clients.length > 1;
if (loggedInWithMultipleClients && state != LoginState.loggedIn) {
_cancelSubs(c.clientName);
Expand All @@ -353,13 +355,13 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
),
);

if (state != LoginState.loggedIn) {
navigatorContext?.go('/rooms');
}
navigatorContext?.go('/rooms');
} else {
setUpToMServicesInLogin(c);
if (state == LoginState.loggedIn) {
navigatorContext?.go('/rooms');
} else {
await getIt.get<HiveCollectionToMDatabase>().clear();
}
}
});
Expand Down

0 comments on commit 696bfd4

Please sign in to comment.