diff --git a/lib/riverpod_controllers/blocks_services.dart b/lib/riverpod_controllers/blocks_services.dart index 866dc1d..097f8ab 100644 --- a/lib/riverpod_controllers/blocks_services.dart +++ b/lib/riverpod_controllers/blocks_services.dart @@ -9,7 +9,6 @@ import '../models/networking/paged_response.dart'; import '../models/networking/paging_data.dart'; import 'connection_manager_services.dart'; import 'networking/friendica_relationship_client_services.dart'; -import 'notification_services.dart'; part 'blocks_services.g.dart'; @@ -35,9 +34,6 @@ class BlocksManager extends _$BlocksManager { await ref .read(connectionModifierProvider(profile, blockedUser).notifier) .upsertConnection(blockedUser); - await ref - .read(notificationsManagerProvider(profile).notifier) - .refreshConnectionRequestNotifications(); }).match( onSuccess: (blockedUser) { _logger.fine( @@ -66,13 +62,10 @@ class BlocksManager extends _$BlocksManager { final blocks = List.from(state.value ?? []); await ref .read(unblockConnectionProvider(profile, connection).future) - .withResult((blockedUser) async { + .withResultAsync((unblocked) async { await ref - .read(connectionModifierProvider(profile, blockedUser).notifier) - .upsertConnection(blockedUser); - await ref - .read(notificationsManagerProvider(profile).notifier) - .refreshConnectionRequestNotifications(); + .read(connectionModifierProvider(profile, unblocked).notifier) + .upsertConnection(unblocked); }).match( onSuccess: (unblockedUser) { _logger.fine( @@ -97,14 +90,17 @@ class BlocksManager extends _$BlocksManager { await ref .read(blocksClientProvider(profile, page).future) - .withResult((returnedBlocks) { + .withResultAsync((returnedBlocks) async { final conBlock = returnedBlocks.data.where((b) => b.id == connection.id).toList(); if (conBlock.isEmpty) { blocks.remove(connection); + await ref + .read(connectionModifierProvider(profile, connection).notifier) + .refreshConnection(true); } else { blocks.add(conBlock.first); - ref + await ref .read(connectionModifierProvider(profile, conBlock.first).notifier) .upsertConnection(conBlock.first); } @@ -147,7 +143,7 @@ class BlocksManager extends _$BlocksManager { } for (final b in blocks) { - ref + await ref .read(connectionModifierProvider(profile, b).notifier) .upsertConnection(b); } diff --git a/lib/riverpod_controllers/connection_manager_services.dart b/lib/riverpod_controllers/connection_manager_services.dart index 5854dbe..1de589d 100644 --- a/lib/riverpod_controllers/connection_manager_services.dart +++ b/lib/riverpod_controllers/connection_manager_services.dart @@ -133,26 +133,6 @@ class ConnectionModifier extends _$ConnectionModifier { return connection; } - void upsertConnectionSync(Connection update) { - ref - .read(_connectionsRepoProvider(profile).future) - .then((repo) => repo.getById(connection.id).match( - onSuccess: (original) { - final forUpsert = update.copy(status: original.status); - repo.upsertConnection( - forUpsert, - ); - state = forUpsert; - }, - onError: (_) { - repo.upsertConnection(update); - state = update; - }, - )) - .then((_) => _sendUpdateNotifications()); - return; - } - Future upsertConnection(Connection update) async { final repo = await ref.read(_connectionsRepoProvider(profile).future); @@ -175,6 +155,7 @@ class ConnectionModifier extends _$ConnectionModifier { state = update; }, ); + _sendUpdateNotifications(); return; } @@ -275,7 +256,6 @@ class ConnectionModifier extends _$ConnectionModifier { ref.invalidate(myContactsProvider); ref.invalidate(connectionByIdProvider(profile, connection.id)); ref.invalidate(connectionByHandleProvider(profile, connection.handle)); - // ref.invalidate(connectionByNameProvider(profile, connection.name)); } Future fullRefresh({ diff --git a/lib/riverpod_controllers/networking/friendica_relationship_client_services.dart b/lib/riverpod_controllers/networking/friendica_relationship_client_services.dart index e4eb665..341ba53 100644 --- a/lib/riverpod_controllers/networking/friendica_relationship_client_services.dart +++ b/lib/riverpod_controllers/networking/friendica_relationship_client_services.dart @@ -281,9 +281,8 @@ Future> unblockConnection( final request = NetworkRequest(url, headers: headers); return await ref .read(httpPostProvider(request).future) - .transform( - (_) => connection.copy(status: ConnectionStatus.blocked), - ) + .andThenAsync((_) async => await ref + .read(connectionWithStatusClientProvider(profile, connection).future)) .execErrorCastAsync(); } diff --git a/lib/screens/user_profile_screen.dart b/lib/screens/user_profile_screen.dart index 8b61047..496a8e8 100644 --- a/lib/screens/user_profile_screen.dart +++ b/lib/screens/user_profile_screen.dart @@ -39,7 +39,7 @@ class _UserProfileScreenState extends ConsumerState { @override Widget build(BuildContext context) { final profile = ref.watch(activeProfileProvider); - final blocksManager = ref.watch(blocksManagerProvider(profile).notifier); + ref.watch(blocksManagerProvider(profile)); final body = ref.watch(connectionByIdProvider(profile, widget.userId)).fold( onSuccess: (connectionProfile) { final notMyProfile = profile.userId != connectionProfile.id; @@ -47,12 +47,8 @@ class _UserProfileScreenState extends ConsumerState { return RefreshIndicator( onRefresh: () async { await ref - .read(connectionModifierProvider( - profile, - connectionProfile, - ).notifier) - .refreshConnection(true); - await blocksManager.updateBlock(connectionProfile); + .read(blocksManagerProvider(profile).notifier) + .updateBlock(connectionProfile); setState(() {}); }, child: SingleChildScrollView( @@ -108,7 +104,7 @@ class _UserProfileScreenState extends ConsumerState { profile, connectionProfile, ), - buildBlockToggle(context, connectionProfile, blocksManager), + buildBlockToggle(context, profile, connectionProfile), ], ], ), @@ -231,25 +227,27 @@ class _UserProfileScreenState extends ConsumerState { Widget buildBlockToggle( BuildContext context, - Connection profile, - BlocksManager manager, + Profile profile, + Connection connection, ) { late Widget blockToggleButton; - switch (profile.status) { + switch (connection.status) { case ConnectionStatus.blocked: blockToggleButton = ElevatedButton( onPressed: isUpdating ? null : () async { - final confirm = - await showYesNoDialog(context, 'Unblock ${profile.name}'); + final confirm = await showYesNoDialog( + context, 'Unblock ${connection.name}'); if (confirm != true) { return; } setState(() { isUpdating = true; }); - await manager.unblockConnection(profile); + await ref + .read(blocksManagerProvider(profile).notifier) + .unblockConnection(connection); setState(() { isUpdating = false; }); @@ -266,15 +264,17 @@ class _UserProfileScreenState extends ConsumerState { onPressed: isUpdating ? null : () async { - final confirm = - await showYesNoDialog(context, 'Block ${profile.name}'); + final confirm = await showYesNoDialog( + context, 'Block ${connection.name}'); if (confirm != true) { return; } setState(() { isUpdating = true; }); - await manager.blockConnection(profile); + await ref + .read(blocksManagerProvider(profile).notifier) + .blockConnection(connection); setState(() { isUpdating = false; });