fix: clear lemma cache on logout and language change (#1603)
This commit is contained in:
parent
3b919b3726
commit
0ab77054d5
2 changed files with 25 additions and 12 deletions
|
|
@ -4,6 +4,7 @@ import 'dart:math';
|
|||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
|
|
@ -58,6 +59,8 @@ class PangeaController {
|
|||
late PStore pStoreService;
|
||||
final pLanguageStore = PangeaLanguage();
|
||||
|
||||
StreamSubscription? _languageStream;
|
||||
|
||||
///Matrix Variables
|
||||
MatrixState matrixState;
|
||||
Matrix matrix;
|
||||
|
|
@ -65,7 +68,7 @@ class PangeaController {
|
|||
int? randomint;
|
||||
PangeaController({required this.matrix, required this.matrixState}) {
|
||||
_setup();
|
||||
_subscribeToMatrixStreams();
|
||||
_subscribeToStreams();
|
||||
randomint = Random().nextInt(2000);
|
||||
}
|
||||
|
||||
|
|
@ -112,7 +115,17 @@ class PangeaController {
|
|||
_logOutfromPangea() {
|
||||
debugPrint("Pangea logout");
|
||||
GoogleAnalytics.logout();
|
||||
pStoreService.clearStorage();
|
||||
_clearCachedData();
|
||||
}
|
||||
|
||||
void _clearCachedData() {
|
||||
GetStorage('mode_list_storage').erase();
|
||||
GetStorage('activity_plan_storage').erase();
|
||||
GetStorage('bookmarked_activities').erase();
|
||||
GetStorage('objective_list_storage').erase();
|
||||
GetStorage('topic_list_storage').erase();
|
||||
GetStorage('lemma_storage').erase();
|
||||
GetStorage().erase();
|
||||
}
|
||||
|
||||
Future<void> checkHomeServerAction() async {
|
||||
|
|
@ -147,6 +160,7 @@ class PangeaController {
|
|||
// Reset cached analytics data
|
||||
MatrixState.pangeaController.putAnalytics.dispose();
|
||||
MatrixState.pangeaController.getAnalytics.dispose();
|
||||
_languageStream?.cancel();
|
||||
break;
|
||||
case LoginState.loggedIn:
|
||||
// Initialize analytics data
|
||||
|
|
@ -324,10 +338,18 @@ class PangeaController {
|
|||
});
|
||||
}
|
||||
|
||||
void _subscribeToMatrixStreams() {
|
||||
void _subscribeToStreams() {
|
||||
matrixState.client.onLoginStateChanged.stream
|
||||
.listen(_handleLoginStateChange);
|
||||
|
||||
// Listen for changes to the user's language settings
|
||||
_languageStream ??= userController.stateStream.listen((update) {
|
||||
if (update is Map<String, dynamic> &&
|
||||
update['prev_target_lang'] != null) {
|
||||
_clearCachedData();
|
||||
}
|
||||
});
|
||||
|
||||
// matrixState.client.onSyncStatus.stream
|
||||
// .where((SyncStatusUpdate event) => event.status == SyncStatus.finished)
|
||||
// .listen(_handleSyncStatusFinished);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:get_storage/get_storage.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/common/controllers/pangea_controller.dart';
|
||||
|
||||
|
|
@ -65,12 +64,4 @@ class PStore {
|
|||
? pangeaController.matrixState.client.userID! + key
|
||||
: key;
|
||||
}
|
||||
|
||||
/// Clears the storage by erasing all data in the box.
|
||||
void clearStorage() {
|
||||
// this could potenitally be interfering with openning database
|
||||
// at the start of the session, which is causing auto log outs on iOS
|
||||
Sentry.addBreadcrumb(Breadcrumb(message: 'Clearing local storage'));
|
||||
_box.erase();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue