add message failed handling

This commit is contained in:
Salvatore Giordano
2020-03-08 09:44:01 +01:00
parent 60c2ccfc24
commit 456e345558
10 changed files with 335 additions and 142 deletions
+8 -9
View File
@@ -644,7 +644,7 @@ class _MessageInputState extends State<MessageInput> {
_mentionsOverlay?.remove();
_mentionsOverlay = null;
FocusScope.of(context).unfocus();
final channel = StreamChannel.of(context).channel;
Future sendingFuture;
Message message;
@@ -659,6 +659,11 @@ class _MessageInputState extends State<MessageInput> {
mentionedUsers:
_mentionedUsers.where((u) => text.contains('@${u.name}')).toList(),
);
if (widget.editMessage.status == MessageSendingStatus.FAILED) {
sendingFuture = channel.sendMessage(message);
}
sendingFuture = StreamChat.of(context).client.updateMessage(message);
} else {
message = Message(
@@ -668,19 +673,13 @@ class _MessageInputState extends State<MessageInput> {
mentionedUsers:
_mentionedUsers.where((u) => text.contains('@${u.name}')).toList(),
);
sendingFuture = StreamChannel.of(context).channel.sendMessage(message);
sendingFuture = channel.sendMessage(message);
}
sendingFuture.then((_) {
sendingFuture.whenComplete(() {
if (widget.onMessageSent != null) {
widget.onMessageSent(message);
}
}).catchError((error) {
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text(error.toString()),
),
);
});
}