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,33 +413,68 @@ class AccountProfileScreen extends HookConsumerWidget {
child: Row( child: Row(
spacing: 8, spacing: 8,
children: [ children: [
Expanded( if (accountRelationship.value == null ||
child: FilledButton.icon( accountRelationship.value!.status > -100)
style: ButtonStyle( Expanded(
backgroundColor: WidgetStatePropertyAll( child: FilledButton.icon(
accountRelationship.value == null style: ButtonStyle(
? null backgroundColor: WidgetStatePropertyAll(
: Theme.of(context).colorScheme.secondary,
),
foregroundColor: WidgetStatePropertyAll(
accountRelationship.value == null
? null
: Theme.of(context).colorScheme.onSecondary,
),
),
onPressed: relationshipAction,
label:
Text(
accountRelationship.value == null accountRelationship.value == null
? 'addFriendShort' ? null
: 'added', : Theme.of(context).colorScheme.secondary,
).tr(), ),
icon: foregroundColor: WidgetStatePropertyAll(
accountRelationship.value == null accountRelationship.value == null
? const Icon(Symbols.person_add) ? null
: const Icon(Symbols.person_check), : 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( 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(