From b2b0891d241d61856d757ec27777bf406e0f0253 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 3 Jul 2025 22:03:12 +0800 Subject: [PATCH] :sparkles: Block user --- lib/screens/account/profile.dart | 102 ++++++++++++++++++++++------- lib/screens/posts/pub_profile.dart | 2 +- 2 files changed, 78 insertions(+), 26 deletions(-) diff --git a/lib/screens/account/profile.dart b/lib/screens/account/profile.dart index 51c8e1d..7271e97 100644 --- a/lib/screens/account/profile.dart +++ b/lib/screens/account/profile.dart @@ -143,6 +143,23 @@ class AccountProfileScreen extends HookConsumerWidget { } } + Future blockAction() async { + showLoadingModal(context); + try { + final client = ref.watch(apiClientProvider); + if (accountRelationship.value == null) { + await client.post('/relationships/${account.value!.id}/block'); + } else { + await client.delete('/relationships/${account.value!.id}/block'); + } + ref.invalidate(accountRelationshipProvider(name)); + } catch (err) { + showErrorAlert(err); + } finally { + if (context.mounted) hideLoadingModal(context); + } + } + Future directMessageAction() async { if (!account.hasValue) return; if (accountChat.value != null) { @@ -396,33 +413,68 @@ class AccountProfileScreen extends HookConsumerWidget { child: Row( spacing: 8, children: [ - Expanded( - child: FilledButton.icon( - style: ButtonStyle( - backgroundColor: WidgetStatePropertyAll( - accountRelationship.value == null - ? null - : Theme.of(context).colorScheme.secondary, - ), - foregroundColor: WidgetStatePropertyAll( - accountRelationship.value == null - ? null - : Theme.of(context).colorScheme.onSecondary, - ), - ), - onPressed: relationshipAction, - label: - Text( + if (accountRelationship.value == null || + accountRelationship.value!.status > -100) + Expanded( + child: FilledButton.icon( + style: ButtonStyle( + backgroundColor: WidgetStatePropertyAll( accountRelationship.value == null - ? 'addFriendShort' - : 'added', - ).tr(), - icon: - accountRelationship.value == null - ? const Icon(Symbols.person_add) - : const Icon(Symbols.person_check), + ? null + : Theme.of(context).colorScheme.secondary, + ), + foregroundColor: WidgetStatePropertyAll( + accountRelationship.value == null + ? null + : Theme.of( + context, + ).colorScheme.onSecondary, + ), + ), + onPressed: relationshipAction, + label: + Text( + accountRelationship.value == null + ? 'addFriendShort' + : 'added', + ).tr(), + icon: + accountRelationship.value == null + ? const Icon(Symbols.person_add) + : const Icon(Symbols.person_check), + ), + ), + if (accountRelationship.value == null || + accountRelationship.value!.status <= -100) + Expanded( + child: FilledButton.icon( + style: ButtonStyle( + backgroundColor: WidgetStatePropertyAll( + accountRelationship.value == null + ? null + : Theme.of(context).colorScheme.secondary, + ), + foregroundColor: WidgetStatePropertyAll( + accountRelationship.value == null + ? null + : Theme.of( + context, + ).colorScheme.onSecondary, + ), + ), + onPressed: blockAction, + label: + Text( + accountRelationship.value == null + ? 'blockUser' + : 'unblockUser', + ).tr(), + icon: + accountRelationship.value == null + ? const Icon(Symbols.block) + : const Icon(Symbols.person_cancel), + ), ), - ), Expanded( child: FilledButton.icon( onPressed: directMessageAction, diff --git a/lib/screens/posts/pub_profile.dart b/lib/screens/posts/pub_profile.dart index adcfd52..19573f7 100644 --- a/lib/screens/posts/pub_profile.dart +++ b/lib/screens/posts/pub_profile.dart @@ -187,7 +187,7 @@ class PublisherProfileScreen extends HookConsumerWidget { ), onTap: () { Navigator.pop(context, true); - context.push('/account/${data.name}'); + context.push('/account/${data.account?.name}'); }, ), Expanded(