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 {
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,

View File

@ -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(