desktop: fix forwarding moving message draft to another chat (#7307)

* desktop: fix forwarding moving message draft to another chat

The same ComposeView is reused when switching chats, so the `chat`
captured by the desktop-only `onDispose` is the chat that was open when
the view was first composed, not the one the message is forwarded from.
The draft was saved under that stale chat id, and when it happened to be
the chat forwarded to, sending the forward restored the draft there.

* plan: justify desktop forward/draft fix and cross-platform findings
This commit is contained in:
Narasimha-sc
2026-07-25 18:23:04 +01:00
committed by GitHub
parent 4b97110fd9
commit 1108e87ee2
2 changed files with 195 additions and 1 deletions
@@ -1352,12 +1352,14 @@ fun ComposeView(
composeState.value = composeState.value.copy(maxFileSize = getMaxFileSize(FileProtocol.XFTP, if (incognito) null else chatModel.currentUser.value?.profile))
}
if (appPlatform.isDesktop) {
// the same ComposeView is reused when switching chats, so `chat` captured by onDispose would be the chat opened first, not the current one
val currentChatId = rememberUpdatedState(chat.id)
// Don't enable this on Android, it breaks it, This method only works on desktop. For Android there is a `KeyChangeEffect(chatModel.chatId.value)`
DisposableEffect(Unit) {
onDispose {
if (chatModel.sharedContent.value is SharedContent.Forward && saveLastDraft && !composeState.value.empty) {
chatModel.draft.value = composeState.value
chatModel.draftChatId.value = chat.id
chatModel.draftChatId.value = currentChatId.value
}
}
}