Add MSC4391 support

Fixes #133
This commit is contained in:
Henry Hiles 2026-11-03 13:12:58 -05:00
commit 3fc33a5ac9
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -0,0 +1,53 @@
import "package:collection/collection.dart";
import "package:hooks_riverpod/hooks_riverpod.dart";
import "package:material_ui/material_ui.dart";
import "package:nexus/controllers/bot_command_draft.dart";
import "package:nexus/models/bot_command_draft.dart";
import "package:nexus/widgets/composer/bot_option_pill.dart";
/// A bot command with its parameters filled in inline, like Discord's slash
/// commands.
class const BotCommandForm(
final BotCommandDraft draft, {
required final VoidCallback onSubmit,
/// Called on backspace in the first parameter while empty.
required final VoidCallback onRemove,
super.key,
}) extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
return Wrap(
spacing: 6,
runSpacing: 6,
crossAxisAlignment: .center,
children: [
Text(
draft.command.prefix,
style: .new(
color: Theme.of(context).colorScheme.primary,
fontWeight: .bold,
),
),
...draft.shown.mapIndexed(
(index, parameter) => BotOptionPill(
parameter,
key: ValueKey(parameter.key),
roomId: draft.roomId,
onSubmit: onSubmit,
onRemove: parameter.optional
? () => ref
.read(
BotCommandDraftController.provider(draft.roomId)
.notifier,
)
.removeOption(parameter.key)
: index == 0
? onRemove
: null,
),
),
],
);
}
}