Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message draft discarded when switching to different chat quickly #3733

Closed
WofWca opened this issue Mar 12, 2024 · 0 comments · Fixed by #4144
Closed

Message draft discarded when switching to different chat quickly #3733

WofWca opened this issue Mar 12, 2024 · 0 comments · Fixed by #4144
Assignees
Labels
bug Something isn't working
Milestone

Comments

@WofWca
Copy link
Collaborator

WofWca commented Mar 12, 2024

  • Operating System (Linux/Mac/Windows/iOS/Android):

  • Delta Chat Version: c878fc7

  • Expected behavior: Draft message saved

  • Actual behavior: Draft message remains unchanged

  • Steps to reproduce the problem:

    1. Open a chat
    2. Write something without pausing for more than a second
    3. Switch to a different chat within a second after making the last change to the draft.
  • Screenshots:
    image

  • Logs:

Example use case: paste something in the message composer and then immediately switch to a different chat.

This has to do with this debounce

this.saveDraft = debounce(() => {
const { text, chatId } = this.state
this.props.updateDraftText(text.trim() === '' ? '' : text, chatId)
}, 1000)

when the chat is switched, the state of the component changes and its text gets assigned the value of the other chat's text, so the draft of the previous chat is lost.
I have attemted to updateDraftText() with prevState.text, but it refuses to save the draft here

if (chatId !== InputChatId) {
log.warn("chat Id and InputChatId don't match, do nothing")
} else {

Then I thought I'd call BackendRemote.rpc.miscSetDraft() anyway, but it looks like it depends on a ton of other state, so we need prevState there as well I guess.

await BackendRemote.rpc.miscSetDraft(
accountId,
chatId,
draft.text,
draft.file !== '' ? draft.file : null,
draft.quote?.kind === 'WithMessage' ? draft.quote.messageId : null,
draft.viewType
)

@Simon-Laux Simon-Laux added this to the New composer milestone Mar 14, 2024
@Simon-Laux Simon-Laux added the bug Something isn't working label Mar 14, 2024
@maxphilippov maxphilippov self-assigned this Oct 15, 2024
maxphilippov added a commit that referenced this issue Nov 19, 2024
- add throttle to packages/shared/utils.ts
- use throttle in saveDraft for messages
- remove explicit call to saveDraft when setting state with new text
- fixes #3733
maxphilippov added a commit that referenced this issue Nov 19, 2024
- add throttle to packages/shared/utils.ts
- use throttle in saveDraft for messages
- remove explicit call to saveDraft when setting state with new text
- fixes #3733
maxphilippov added a commit that referenced this issue Nov 20, 2024
- add throttle to packages/shared/utils.ts
- use throttle in saveDraft for messages
- remove explicit call to saveDraft when setting state with new text
- fixes #3733
maxphilippov added a commit that referenced this issue Nov 27, 2024
- add throttle to packages/shared/utils.ts
- use throttle in saveDraft for messages
- remove explicit call to saveDraft when setting state with new text
- fixes #3733
maxphilippov added a commit that referenced this issue Nov 27, 2024
- add throttle to packages/shared/utils.ts
- use throttle in saveDraft for messages
- remove explicit call to saveDraft when setting state with new text
- fixes #3733
@nicodh nicodh closed this as completed in d1fbc7a Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants