diff --git a/lib/data/interfaces/groups_repo.intf.dart b/lib/data/interfaces/groups_repo.intf.dart index c4ceec3..c0133e9 100644 --- a/lib/data/interfaces/groups_repo.intf.dart +++ b/lib/data/interfaces/groups_repo.intf.dart @@ -5,6 +5,8 @@ import '../../models/exec_error.dart'; import '../../models/group_data.dart'; abstract class IGroupsRepo { + void clear(); + void addAllGroups(List groups); void addConnectionToGroup(GroupData group, Connection connection); diff --git a/lib/data/interfaces/hashtag_repo_intf.dart b/lib/data/interfaces/hashtag_repo_intf.dart index ae9f17d..403cc06 100644 --- a/lib/data/interfaces/hashtag_repo_intf.dart +++ b/lib/data/interfaces/hashtag_repo_intf.dart @@ -1,11 +1,9 @@ import '../../models/hashtag.dart'; -class IHashtagRepo { - void add(Hashtag tag) { - throw UnimplementedError(); - } +abstract class IHashtagRepo { + Future clear(); - List getMatchingHashTags(String text) { - throw UnimplementedError(); - } + void add(Hashtag tag); + + List getMatchingHashTags(String text); } diff --git a/lib/data/memory/memory_groups_repo.dart b/lib/data/memory/memory_groups_repo.dart index 2251754..4555e71 100644 --- a/lib/data/memory/memory_groups_repo.dart +++ b/lib/data/memory/memory_groups_repo.dart @@ -10,6 +10,13 @@ class MemoryGroupsRepo implements IGroupsRepo { final _connectionsForGroup = >{}; final _myGroups = {}; + @override + void clear() { + _groupsForConnection.clear(); + _connectionsForGroup.clear(); + _myGroups.clear(); + } + @override Result, ExecError> getGroupsForUser(String id) { if (!_groupsForConnection.containsKey(id)) { diff --git a/lib/data/objectbox/objectbox_hashtag_repo.dart b/lib/data/objectbox/objectbox_hashtag_repo.dart index 46c741b..d3fccd2 100644 --- a/lib/data/objectbox/objectbox_hashtag_repo.dart +++ b/lib/data/objectbox/objectbox_hashtag_repo.dart @@ -11,6 +11,11 @@ class ObjectBoxHashtagRepo implements IHashtagRepo { box = getIt().store.box(); } + @override + Future clear() async { + await box.removeAllAsync(); + } + @override void add(Hashtag tag) { box.putAsync(tag); diff --git a/lib/di_initialization.dart b/lib/di_initialization.dart index 597328d..eff785f 100644 --- a/lib/di_initialization.dart +++ b/lib/di_initialization.dart @@ -127,3 +127,49 @@ Future updateProfileDependencyInjectors(Profile profile) async { ), ); } + +void clearCaches() { + getIt>().activeEntry.match( + onSuccess: (repo) => repo.clear(), + onError: (error) => + _logger.severe('Error clearing IConnections Repo: $error'), + ); + + getIt>().activeEntry.match( + onSuccess: (service) => service.clear(), + onError: (error) => + _logger.severe('Error clearing DirectMessageService Repo: $error'), + ); + + getIt>().activeEntry.match( + onSuccess: (service) => service.clear(), + onError: (error) => + _logger.severe('Error clearing EntryManagerService Repo: $error'), + ); + + getIt>().activeEntry.match( + onSuccess: (manager) => manager.clear(), + onError: (error) => + _logger.severe('Error clearing FollowRequestsManager Repo: $error'), + ); + + getIt>().activeEntry.match( + onSuccess: (service) => service.clear(), + onError: (error) => + _logger.severe('Error clearing GalleryService Repo: $error'), + ); + + getIt().clear(); + + getIt>().activeEntry.match( + onSuccess: (manager) => manager.clear(), + onError: (error) => + _logger.severe('Error clearing NotificationsManager Repo: $error'), + ); + + getIt>().activeEntry.match( + onSuccess: (manager) => manager.clear(), + onError: (error) => + _logger.severe('Error clearing TimelineManager Repo: $error'), + ); +} diff --git a/lib/friendica_client/friendica_client.dart b/lib/friendica_client/friendica_client.dart index f35d1ef..475b9c2 100644 --- a/lib/friendica_client/friendica_client.dart +++ b/lib/friendica_client/friendica_client.dart @@ -400,7 +400,7 @@ class NotificationsClient extends FriendicaClient { final url = 'https://$serverName/api/v1/notifications/${notification.id}/dismiss'; final request = Uri.parse(url); - _logger.finest(() => 'Clearing unread notification for $notification'); + _logger.fine(() => 'Clearing unread notification for $notification'); final response = await postUrl(request, {}, headers: _headers); return response.mapValue((value) => true); } @@ -413,7 +413,7 @@ class RelationshipsClient extends FriendicaClient { FutureResult>, ExecError> getMyFollowing( PagingData page) async { - _logger.finest(() => 'Getting following with paging data $page'); + _logger.fine(() => 'Getting following with paging data $page'); _networkStatusService.startConnectionUpdateStatus(); final myId = profile.userId; final baseUrl = 'https://$serverName/api/v1/accounts/$myId'; diff --git a/lib/globals.dart b/lib/globals.dart index ba843f4..5669b07 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -88,9 +88,3 @@ Future showChooseOptions( }, ); } - -// void clearCaches() { -// getIt().clear(); -// getIt().clear(); -// getIt().clear(); -// } diff --git a/lib/screens/follow_request_adjudication_screen.dart b/lib/screens/follow_request_adjudication_screen.dart index 7af8fcc..b2a1878 100644 --- a/lib/screens/follow_request_adjudication_screen.dart +++ b/lib/screens/follow_request_adjudication_screen.dart @@ -47,7 +47,7 @@ class _FollowRequestAdjudicationScreenState .getByUserId(widget.userId) .mapValue((request) => request.connection); } else { - result = cm.getById(widget.userId); + result = cm.getById(widget.userId, forceUpdate: true); } late final Widget body; @@ -56,7 +56,7 @@ class _FollowRequestAdjudicationScreenState } else { final contact = result.value; final contactStatus = cm - .getById(widget.userId) + .getById(widget.userId, forceUpdate: true) .getValueOrElse(() => Connection(status: ConnectionStatus.none)) .status; diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart index ee36300..100372e 100644 --- a/lib/screens/settings_screen.dart +++ b/lib/screens/settings_screen.dart @@ -5,6 +5,8 @@ import 'package:provider/provider.dart'; import '../controls/responsive_max_width.dart'; import '../controls/standard_appbar.dart'; +import '../di_initialization.dart'; +import '../globals.dart'; import '../services/setting_service.dart'; import '../utils/theme_mode_extensions.dart'; @@ -23,6 +25,7 @@ class SettingsScreen extends StatelessWidget { buildLowBandwidthWidget(settings), buildThemeWidget(settings), if (!kReleaseMode) buildColorBlindnessTestSettings(settings), + buildClearCaches(context), ], ), ), @@ -72,4 +75,23 @@ class SettingsScreen extends StatelessWidget { }), ); } + + Widget buildClearCaches(BuildContext context) { + return ListTile( + title: const Text('Clear local caches'), + subtitle: const Text('This does not affect server side data at all.'), + trailing: ElevatedButton( + onPressed: () async { + final confirm = await showYesNoDialog(context, + 'Are you sure you want to clear all local data for this account?'); + if (confirm != true) { + return; + } + + clearCaches(); + }, + child: const Text('Clear'), + ), + ); + } } diff --git a/lib/screens/user_profile_screen.dart b/lib/screens/user_profile_screen.dart index 5f68ee9..589804e 100644 --- a/lib/screens/user_profile_screen.dart +++ b/lib/screens/user_profile_screen.dart @@ -27,6 +27,14 @@ class UserProfileScreen extends StatefulWidget { class _UserProfileScreenState extends State { var isUpdating = false; + @override + void initState() { + super.initState(); + getIt>().activeEntry.withResult( + (m) => m.getById(widget.userId, forceUpdate: true), + ); + } + @override Widget build(BuildContext context) { final manager = context diff --git a/lib/services/connections_manager.dart b/lib/services/connections_manager.dart index 899044f..7bdd254 100644 --- a/lib/services/connections_manager.dart +++ b/lib/services/connections_manager.dart @@ -23,6 +23,13 @@ class ConnectionsManager extends ChangeNotifier { ConnectionsManager(this.conRepo, this.groupsRepo); + void clear() { + conRepo.clear(); + groupsRepo.clear(); + groupsNotInitialized = true; + notifyListeners(); + } + List getKnownUsersByName(String name) { return conRepo.getKnownUsersByName(name); } @@ -200,13 +207,12 @@ class ConnectionsManager extends ChangeNotifier { } List getMyGroups() { - final myGroups = groupsRepo.getMyGroups(); if (groupsNotInitialized) { - groupsNotInitialized = true; + groupsNotInitialized = false; _updateMyGroups(true); } - return myGroups; + return groupsRepo.getMyGroups(); } Result, ExecError> getGroupMembers(GroupData group) { @@ -325,9 +331,9 @@ class ConnectionsManager extends ChangeNotifier { ); } - Result getById(String id) { + Result getById(String id, {bool forceUpdate = false}) { return conRepo.getById(id).andThenSuccess((c) { - if (c.status == ConnectionStatus.unknown) { + if (forceUpdate) { _refreshConnection(c, true); } return c; diff --git a/lib/services/direct_message_service.dart b/lib/services/direct_message_service.dart index 78938ef..5f134cd 100644 --- a/lib/services/direct_message_service.dart +++ b/lib/services/direct_message_service.dart @@ -18,6 +18,12 @@ class DirectMessageService extends ChangeNotifier { final _threads = {}; var _firstLoading = true; + void clear() { + _threads.clear(); + _firstLoading = true; + notifyListeners(); + } + List getThreads({bool unreadyOnly = false}) { if (_threads.isEmpty && _firstLoading) { updateThreads(); diff --git a/lib/services/follow_requests_manager.dart b/lib/services/follow_requests_manager.dart index 01e1b29..0ccb58e 100644 --- a/lib/services/follow_requests_manager.dart +++ b/lib/services/follow_requests_manager.dart @@ -17,6 +17,10 @@ class FollowRequestsManager extends ChangeNotifier { List get requests => UnmodifiableListView(_requests.values); + void clear() { + _requests.clear(); + } + Result getByUserId(String id) { final request = _requests[id]; return request != null diff --git a/lib/services/gallery_service.dart b/lib/services/gallery_service.dart index de07029..8d00c72 100644 --- a/lib/services/gallery_service.dart +++ b/lib/services/gallery_service.dart @@ -18,6 +18,14 @@ class GalleryService extends ChangeNotifier { bool get loaded => _loaded; + void clear() { + _galleries.clear(); + _galleryPages.clear(); + _images.clear(); + _loaded = false; + notifyListeners(); + } + List getGalleries() { if (_galleries.isEmpty) { updateGalleries(); diff --git a/lib/services/hashtag_service.dart b/lib/services/hashtag_service.dart index a9c6ea9..27baa45 100644 --- a/lib/services/hashtag_service.dart +++ b/lib/services/hashtag_service.dart @@ -11,6 +11,11 @@ class HashtagService extends ChangeNotifier { repo = getIt(); } + Future clear() async { + await repo.clear(); + notifyListeners(); + } + void add(Hashtag tag) { repo.add(tag); notifyListeners(); diff --git a/lib/services/interactions_manager.dart b/lib/services/interactions_manager.dart index faa4759..506f382 100644 --- a/lib/services/interactions_manager.dart +++ b/lib/services/interactions_manager.dart @@ -13,6 +13,12 @@ class InteractionsManager extends ChangeNotifier { final _likesByStatusId = >{}; final _resharesByStatusId = >{}; + void clear() { + _likesByStatusId.clear(); + _resharesByStatusId.clear(); + notifyListeners(); + } + List getLikes(String statusId) { if (!_likesByStatusId.containsKey(statusId)) { updateLikesForStatus(statusId); diff --git a/lib/services/notifications_manager.dart b/lib/services/notifications_manager.dart index 5877028..074ce0c 100644 --- a/lib/services/notifications_manager.dart +++ b/lib/services/notifications_manager.dart @@ -65,6 +65,8 @@ class NotificationsManager extends ChangeNotifier { void clear() { _notifications.clear(); _pm.clear(); + _firstLoad = true; + notifyListeners(); } FutureResult, ExecError> updateNotifications() async { diff --git a/lib/services/timeline_manager.dart b/lib/services/timeline_manager.dart index a0efabb..df239bd 100644 --- a/lib/services/timeline_manager.dart +++ b/lib/services/timeline_manager.dart @@ -35,9 +35,10 @@ class TimelineManager extends ChangeNotifier { TimelineManager(this.groupsRepo, this.entryManagerService); void clear() { + groupsNotInitialized = true; cachedTimelines.clear(); entryManagerService.clear(); - groupsRepo.clearMyGroups(); + groupsRepo.clear(); notifyListeners(); }