mirror of
https://gitlab.com/mysocialportal/relatica
synced 2024-10-18 11:13:31 +00:00
Add user ability to purge memory and persistent caches
This commit is contained in:
parent
61d12542fb
commit
bf13e0674b
5 changed files with 44 additions and 9 deletions
|
@ -4,6 +4,10 @@ import '../../models/connection.dart';
|
|||
import '../../models/exec_error.dart';
|
||||
|
||||
class IConnectionsRepo {
|
||||
void clear() {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
bool addConnection(Connection connection) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
|
|
@ -9,6 +9,13 @@ class MemoryConnectionsRepo implements IConnectionsRepo {
|
|||
final _connectionsByName = <String, Connection>{};
|
||||
final _myContacts = <Connection>[];
|
||||
|
||||
@override
|
||||
void clear() {
|
||||
_connectionsById.clear();
|
||||
_connectionsByName.clear();
|
||||
_myContacts.clear();
|
||||
}
|
||||
|
||||
@override
|
||||
bool addAllConnections(Iterable<Connection> newConnections) {
|
||||
bool result = true;
|
||||
|
|
|
@ -16,6 +16,12 @@ class ObjectBoxConnectionsRepo implements IConnectionsRepo {
|
|||
box = getIt<ObjectBoxCache>().store.box<Connection>();
|
||||
}
|
||||
|
||||
@override
|
||||
void clear() {
|
||||
memCache.clear();
|
||||
box.removeAll();
|
||||
}
|
||||
|
||||
@override
|
||||
bool addAllConnections(Iterable<Connection> newConnections) {
|
||||
memCache.addAllConnections(newConnections);
|
||||
|
@ -40,9 +46,10 @@ class ObjectBoxConnectionsRepo implements IConnectionsRepo {
|
|||
return _getConnection(
|
||||
Connection_.id.equals(id),
|
||||
).mapError(
|
||||
(error) => error.copy(
|
||||
message: "Can't find Connection for ID: $id",
|
||||
),
|
||||
(error) =>
|
||||
error.copy(
|
||||
message: "Can't find Connection for ID: $id",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -55,9 +62,10 @@ class ObjectBoxConnectionsRepo implements IConnectionsRepo {
|
|||
return _getConnection(
|
||||
Connection_.name.equals(name),
|
||||
).mapError(
|
||||
(error) => error.copy(
|
||||
message: "Can't find Connection for ID: $name",
|
||||
),
|
||||
(error) =>
|
||||
error.copy(
|
||||
message: "Can't find Connection for ID: $name",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -65,9 +73,9 @@ class ObjectBoxConnectionsRepo implements IConnectionsRepo {
|
|||
List<Connection> getKnownUsersByName(String name) {
|
||||
return box
|
||||
.query(
|
||||
Connection_.name.contains(name, caseSensitive: false) |
|
||||
Connection_.handle.contains(name, caseSensitive: false),
|
||||
)
|
||||
Connection_.name.contains(name, caseSensitive: false) |
|
||||
Connection_.handle.contains(name, caseSensitive: false),
|
||||
)
|
||||
.build()
|
||||
.find();
|
||||
}
|
||||
|
|
|
@ -2,9 +2,12 @@ import 'package:flutter/material.dart';
|
|||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../controls/app_bottom_nav_bar.dart';
|
||||
import '../data/interfaces/connections_repo_intf.dart';
|
||||
import '../globals.dart';
|
||||
import '../routes.dart';
|
||||
import '../services/auth_service.dart';
|
||||
import '../services/notifications_manager.dart';
|
||||
import '../services/timeline_manager.dart';
|
||||
|
||||
class MenusScreen extends StatelessWidget {
|
||||
static const menuButtonWidth = 350.0;
|
||||
|
@ -17,6 +20,15 @@ class MenusScreen extends StatelessWidget {
|
|||
buildMenuButton('Profile', () => context.pushNamed(ScreenPaths.profile)),
|
||||
buildMenuButton(
|
||||
'Settings', () => context.pushNamed(ScreenPaths.settings)),
|
||||
buildMenuButton('Clear Caches', () async {
|
||||
final confirm = await showYesNoDialog(
|
||||
context, 'You want to clear all memory and disk cache data?');
|
||||
if (confirm == true) {
|
||||
getIt<TimelineManager>().clear();
|
||||
getIt<IConnectionsRepo>().clear();
|
||||
getIt<NotificationsManager>().clear();
|
||||
}
|
||||
}),
|
||||
buildMenuButton('Logout', () async {
|
||||
final confirm = await showYesNoDialog(context, 'Log out account?');
|
||||
if (confirm == true) {
|
||||
|
|
|
@ -28,6 +28,10 @@ class NotificationsManager extends ChangeNotifier {
|
|||
return result;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_notifications.clear();
|
||||
}
|
||||
|
||||
FutureResult<List<UserNotification>, ExecError> updateNotifications() async {
|
||||
final auth = getIt<AuthService>();
|
||||
final clientResult = auth.currentClient;
|
||||
|
|
Loading…
Reference in a new issue