Block user

This commit is contained in:
LittleSheep 2025-07-03 22:03:12 +08:00
parent 274168d4bc
commit b2b0891d24
2 changed files with 78 additions and 26 deletions

View File

@ -143,6 +143,23 @@ class AccountProfileScreen extends HookConsumerWidget {
} }
} }
Future<void> 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<void> directMessageAction() async { Future<void> directMessageAction() async {
if (!account.hasValue) return; if (!account.hasValue) return;
if (accountChat.value != null) { if (accountChat.value != null) {
@ -396,6 +413,8 @@ class AccountProfileScreen extends HookConsumerWidget {
child: Row( child: Row(
spacing: 8, spacing: 8,
children: [ children: [
if (accountRelationship.value == null ||
accountRelationship.value!.status > -100)
Expanded( Expanded(
child: FilledButton.icon( child: FilledButton.icon(
style: ButtonStyle( style: ButtonStyle(
@ -407,7 +426,9 @@ class AccountProfileScreen extends HookConsumerWidget {
foregroundColor: WidgetStatePropertyAll( foregroundColor: WidgetStatePropertyAll(
accountRelationship.value == null accountRelationship.value == null
? null ? null
: Theme.of(context).colorScheme.onSecondary, : Theme.of(
context,
).colorScheme.onSecondary,
), ),
), ),
onPressed: relationshipAction, onPressed: relationshipAction,
@ -423,6 +444,37 @@ class AccountProfileScreen extends HookConsumerWidget {
: const Icon(Symbols.person_check), : 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( Expanded(
child: FilledButton.icon( child: FilledButton.icon(
onPressed: directMessageAction, onPressed: directMessageAction,

View File

@ -187,7 +187,7 @@ class PublisherProfileScreen extends HookConsumerWidget {
), ),
onTap: () { onTap: () {
Navigator.pop(context, true); Navigator.pop(context, true);
context.push('/account/${data.name}'); context.push('/account/${data.account?.name}');
}, },
), ),
Expanded( Expanded(