Skip to content

ui: preserve input text until message send succeeds#562

Open
desgua wants to merge 2 commits into
d99kris:masterfrom
desgua:myfork/keep_text_until_successfully_sent
Open

ui: preserve input text until message send succeeds#562
desgua wants to merge 2 commits into
d99kris:masterfrom
desgua:myfork/keep_text_until_successfully_sent

Conversation

@desgua

@desgua desgua commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Prevents input buffer from clearing immediately upon hitting send shortcut, avoiding message loss during silent network drops. The entry field is now cleared only when SendMessageNotify confirms a successful transmission.

Problem
Currently, when a user sends a message, UiModel::Impl::SendMessage() immediately clears the input field buffer (entryStr) before the background network thread ever transmits the payload or receives a confirmation from the backend protocol.

If the user suffers a temporary or silent network disconnection, the message is dropped entirely by the backend, but the text has already vanished from the interface. The user has no way of knowing the message failed to send unless they monitor log traces, and their typed text is permanently lost.

Proposed Solution
This PR shifts the responsibility of clearing the input entry state from the optimistic SendMessage() invocation to the asynchronous protocol response handler.

src/uimodel.cpp (SendMessage): Removed the immediate execution of entryStr.clear(), entryPos = 0, and UpdateEntry().

src/uimodel.cpp (MessageHandler): Inside the SendMessageNotifyType switch case, we now explicitly check the sendMessageNotify->success state.

On Success: The message buffer and cursor position for that specific profileId and chatId are cleared and the UI is updated.

On Failure: The state is left intact. The text remains visible in the input field, allowing the user to easily attempt a re-send once their network stability returns.

Prevents input buffer from clearing immediately upon hitting enter, avoiding message loss during silent network drops. The entry field is now cleared only when SendMessageNotify confirms a successful transmission.
@d99kris

d99kris commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Is there any mechanism preventing the user from sending the same message twice?
(e.g. pressing ctrl-x twice quickly)

@desgua

desgua commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

I think that's a valid point. I will see if I find a way to avoid sending the same message twice and I will update asap.

@desgua

desgua commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

I think a good approach would be to check if the user is trying to send the exact same message in less than a few seconds and in that case skip it. What do you think?

…ce after changing nchat behavior to keep the input text until message send succeeds
@desgua

desgua commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

I added a 5 seconds "cooldown" for messages that are exact the same.

@d99kris d99kris self-assigned this Jul 19, 2026
@desgua

desgua commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Another possible solution would be to show the sent message on history and mark with a signal showing it failed to deliver. That is what web.whatsapp.com does.
Other idea is to restore the sent message to the input field and alert the user with a notification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants