implemented keyboard-aware back navigation and refined message sending logic to prevent phantom drafts and handle mid-send navigation
This commit is contained in:
@@ -110,17 +110,27 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
if (_textBoxController.text.isEmpty) return;
|
||||
final text = _textBoxController.text;
|
||||
final replyTo = chatBloc.state.data?.referenceMessageId?.toString();
|
||||
final ownToken = widget.sendToToken;
|
||||
setState(() => _sendError = null);
|
||||
await SendMessage(
|
||||
widget.sendToToken,
|
||||
ownToken,
|
||||
SendMessageParams(text, replyTo: replyTo),
|
||||
).run();
|
||||
if (!mounted) return;
|
||||
chatBloc.refresh();
|
||||
_textBoxController.text = '';
|
||||
// Reached only on success — SendMessage.run() throws on failure and
|
||||
// skips this block, leaving the persisted draft as a recovery aid.
|
||||
// Drafts live on the global SettingsCubit keyed by token, so clear
|
||||
// them even when the user navigated away mid-send — otherwise the
|
||||
// sent message lingers as a phantom draft on the chat list.
|
||||
_setDraft('');
|
||||
chatBloc.setReferenceMessageId(null);
|
||||
_setDraftReply(null);
|
||||
// The global ChatBloc may already point at a different chat (user
|
||||
// switched mid-send); only touch it while it still references us.
|
||||
if (chatBloc.state.data?.currentToken == ownToken) {
|
||||
chatBloc.setReferenceMessageId(null);
|
||||
chatBloc.refresh();
|
||||
}
|
||||
if (!mounted) return;
|
||||
_textBoxController.text = '';
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user