mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-11 11:59:56 +00:00
* ios, android, desktop: fix message being sent leaking into another chat Compose state is shared between the chats opened in the same view, and the send is launched in a scope that outlives the chat, so a send that was still in flight when the chat was switched put its message (with the reply context) into the compose state and then the draft of another chat, and a late success cleared whatever was typed in the meantime. The message being sent is no longer kept in the compose state when leaving the chat, and the compose state is only cleared or restored after sending if it still holds the message that was sent - the same check is used by the other senders that show progress in the compose. A message that failed to send is restored in the chat it was composed in, or kept as its draft when another chat is open (iOS has no failed message restore, there the message is dropped as before). * android, desktop: keep only the chat switch fix Revert the iOS changes and the same check in the three senders that connect a prepared chat, leaving the fix for the compose state shared between the chats opened in one view. * plan: document what the narrowed change leaves to the connect senders * android, desktop: use the same check where the sending flag is shared The senders that connect a prepared chat set the same inProgress flag, so a connect completing after the chat was switched cleared it for a send started in the chat opened next, and that sent message was then left in the compose. * android, desktop: keep the live message clauses inside the open chat check live and cs.liveMessage != null were alternatives to chatIsOpen, which holds only while a live message is always sent to the chat that is open. #7323 removes that: the live message committed by a chat switch is sent to the chat it was composed in, while this view already shows another one, so an unguarded clause here clears that chat's compose state - the leak this fix exists to prevent. liveSend stays an alternative to inProgress inside the guard, so a live send behaves exactly as before while its chat is open, and it is excluded from the restore/draft branch, which would otherwise write a draft on every failing keystroke send once that chat is no longer open. On this branch the only behaviour change is a live send completing after its chat was left, which now leaves the opened chat alone. Also load the draft of the chat opened next when the compose state is cleared on switching away from a send in flight: clearState() returns before the branch that loads a draft, so that draft was never shown, and being in the slot but in no compose state it was then dropped by clearPrevDraft on the next chat switch. * plan: explain why live sends are guarded by the open chat check Records that the exemption in "Deliberately unchanged" is from a guard based on inProgress, not from chatIsOpen, and why the earlier form broke once #7323 sends a live message to a chat other than the one open.