mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-01-23 10:34:25 +01:00
/commands: missing command dialog
When sending a message, show an alert dialog if a command is not recognized, offering to either cancel or send as text.
This commit is contained in:
parent
7d25bbb539
commit
65b1215187
@ -86,6 +86,18 @@
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"description": "Usage hint for the command /myroomavatar"
|
"description": "Usage hint for the command /myroomavatar"
|
||||||
},
|
},
|
||||||
|
"commandInvalid": "Command invalid",
|
||||||
|
"@commandInvalid": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"commandMissing": "{command} is not a command.",
|
||||||
|
"@commandMissing": {
|
||||||
|
"type": "text",
|
||||||
|
"placeholders": {
|
||||||
|
"command": {}
|
||||||
|
},
|
||||||
|
"description": "State that {command} is not a valid /command."
|
||||||
|
},
|
||||||
"editRoomAliases": "Edit room aliases",
|
"editRoomAliases": "Edit room aliases",
|
||||||
"@editRoomAliases": {
|
"@editRoomAliases": {
|
||||||
"type": "text",
|
"type": "text",
|
||||||
@ -1849,6 +1861,10 @@
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"placeholders": {}
|
"placeholders": {}
|
||||||
},
|
},
|
||||||
|
"sendAsText": "Send as text",
|
||||||
|
"@sendAsText": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
"sendAudio": "Send audio",
|
"sendAudio": "Send audio",
|
||||||
"@sendAudio": {
|
"@sendAudio": {
|
||||||
"type": "text",
|
"type": "text",
|
||||||
|
@ -215,10 +215,31 @@ class ChatController extends State<Chat> {
|
|||||||
|
|
||||||
TextEditingController sendController = TextEditingController();
|
TextEditingController sendController = TextEditingController();
|
||||||
|
|
||||||
void send() {
|
Future<void> send() async {
|
||||||
if (sendController.text.trim().isEmpty) return;
|
if (sendController.text.trim().isEmpty) return;
|
||||||
|
var parseCommands = true;
|
||||||
|
|
||||||
|
final commandMatch = RegExp(r'^\/(\w+)').firstMatch(sendController.text);
|
||||||
|
if (commandMatch != null &&
|
||||||
|
!room.client.commands.keys.contains(commandMatch[1].toLowerCase())) {
|
||||||
|
final l10n = L10n.of(context);
|
||||||
|
final dialogResult = await showOkCancelAlertDialog(
|
||||||
|
context: context,
|
||||||
|
useRootNavigator: false,
|
||||||
|
title: l10n.commandInvalid,
|
||||||
|
message: l10n.commandMissing(commandMatch[0]),
|
||||||
|
okLabel: l10n.sendAsText,
|
||||||
|
cancelLabel: l10n.cancel,
|
||||||
|
);
|
||||||
|
if (dialogResult == null || dialogResult == OkCancelResult.cancel) return;
|
||||||
|
parseCommands = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore: unawaited_futures
|
||||||
room.sendTextEvent(sendController.text,
|
room.sendTextEvent(sendController.text,
|
||||||
inReplyTo: replyEvent, editEventId: editEvent?.eventId);
|
inReplyTo: replyEvent,
|
||||||
|
editEventId: editEvent?.eventId,
|
||||||
|
parseCommands: parseCommands);
|
||||||
sendController.value = TextEditingValue(
|
sendController.value = TextEditingValue(
|
||||||
text: pendingText,
|
text: pendingText,
|
||||||
selection: TextSelection.collapsed(offset: 0),
|
selection: TextSelection.collapsed(offset: 0),
|
||||||
|
Loading…
Reference in New Issue
Block a user