@@ -4,7 +4,6 @@ import 'dart:math';
44import 'package:flutter/material.dart' ;
55import 'package:flutter/services.dart' ;
66import 'package:flutter_it/flutter_it.dart' ;
7- import 'package:future_loading_dialog/future_loading_dialog.dart' ;
87import 'package:matrix/matrix.dart' ;
98import 'package:yaru/yaru.dart' ;
109
@@ -48,8 +47,6 @@ class _ChatInputState extends State<ChatInput> {
4847 // Check if the "@"-Key has been pressed
4948 if (_sendController.text.contains ('@' )) {
5049 printMessageInDebugMode ('@ key pressed' );
51-
52- return KeyEventResult .handled;
5350 }
5451
5552 final enterPressedWithoutShift =
@@ -63,7 +60,7 @@ class _ChatInputState extends State<ChatInput> {
6360 );
6461
6562 if (enterPressedWithoutShift) {
66- send (context );
63+ send ();
6764 return KeyEventResult .handled;
6865 } else if (event is KeyRepeatEvent ) {
6966 // Disable holding enter
@@ -82,33 +79,14 @@ class _ChatInputState extends State<ChatInput> {
8279 super .dispose ();
8380 }
8481
85- Future <void > send (BuildContext context) async =>
86- di <DraftManager >().filesDrafts.containsKey (widget.room.id) &&
87- di <DraftManager >().filesDrafts[widget.room.id]! .isNotEmpty
88- ? showFutureLoadingDialog (
89- context: context,
90- title: context.l10n.sendingAttachment,
91- future: () => di <DraftManager >()
92- .send (room: widget.room)
93- .timeout (const Duration (seconds: 30 )),
94- barrierDismissible: true ,
95- backLabel: context.l10n.close,
96- onError: (error) {
97- if (error is TimeoutException ) {
98- return context.l10n.oopsSomethingWentWrong;
99- }
100- return error.toString ();
101- },
102- ).then ((res) {
103- if (res.isValue) {
104- _sendController.clear ();
105- _sendNode.requestFocus ();
106- }
107- })
108- : di <DraftManager >().send (room: widget.room).then ((_) {
109- _sendController.clear ();
110- _sendNode.requestFocus ();
111- });
82+ void send () {
83+ final isRunning = di <DraftManager >().sendCommand.isRunning;
84+ if (isRunning.value) return ;
85+ di <DraftManager >().sendCommand.runAsync (widget.room).then ((_) {
86+ _sendController.clear ();
87+ _sendNode.requestFocus ();
88+ });
89+ }
11290
11391 @override
11492 Widget build (BuildContext context) {
@@ -122,6 +100,8 @@ class _ChatInputState extends State<ChatInput> {
122100 (ChatManager m) => m.archiveActive,
123101 );
124102
103+ final sending = watchValue ((DraftManager m) => m.sendCommand.isRunning);
104+
125105 final replyEvent = watchPropertyValue ((DraftManager m) => m.replyEvent);
126106
127107 final editEvent = watchPropertyValue (
@@ -274,9 +254,12 @@ class _ChatInputState extends State<ChatInput> {
274254 padding: EdgeInsets .zero,
275255 icon: transform,
276256 onPressed:
277- attaching || archiveActive || unAcceptedDirectChat
257+ sending ||
258+ attaching ||
259+ archiveActive ||
260+ unAcceptedDirectChat
278261 ? null
279- : () async => send (context ),
262+ : () => send (),
280263 ),
281264 ],
282265 ),
0 commit comments