Fix block status not propagating properly.

merge-requests/67/merge
Hank Grabowski 2024-12-20 09:45:39 -05:00
rodzic 14a69d2a72
commit 7e990cfe0c
4 zmienionych plików z 29 dodań i 54 usunięć

Wyświetl plik

@ -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<Connection>.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);
}

Wyświetl plik

@ -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<void> 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<void> fullRefresh({

Wyświetl plik

@ -281,9 +281,8 @@ Future<Result<Connection, ExecError>> 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();
}

Wyświetl plik

@ -39,7 +39,7 @@ class _UserProfileScreenState extends ConsumerState<UserProfileScreen> {
@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<UserProfileScreen> {
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<UserProfileScreen> {
profile,
connectionProfile,
),
buildBlockToggle(context, connectionProfile, blocksManager),
buildBlockToggle(context, profile, connectionProfile),
],
],
),
@ -231,25 +227,27 @@ class _UserProfileScreenState extends ConsumerState<UserProfileScreen> {
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<UserProfileScreen> {
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;
});