Skip to content

fix: whatsapp archive lthash mismatch and UI history refresh#504

Open
asemarafa wants to merge 1 commit intod99kris:masterfrom
asemarafa:fix-whatsapp-archive-lthash
Open

fix: whatsapp archive lthash mismatch and UI history refresh#504
asemarafa wants to merge 1 commit intod99kris:masterfrom
asemarafa:fix-whatsapp-archive-lthash

Conversation

@asemarafa
Copy link
Copy Markdown
Contributor

This PR addresses the issue where WhatsApp chats fail to sync their archive/unarchive state properly when modified from another device (e.g.,
a phone) while nchat is offline or disconnected.

What this fixes:

  1. ErrMismatchingLTHash in whatsmeow: When the local app state hash does not match the server's hash, whatsmeow previously failed silently on
    ErrMismatchingLTHash. This patch catches the error and explicitly sends a BuildAppStateRecoveryRequest to heal the local state.

  2. UI History Refresh (uimodel.cpp): When a chat is unarchived, the application sends a request for new messages. However, prior message
    requests might have been silently dropped by the NewMessagesNotify handler when the chat was still considered archived locally. This
    clears any previously requested message IDs and calls UpdateHistory() to ensure the UI accurately reflects any messages that arrived while
    the chat was archived.

@d99kris d99kris self-assigned this Mar 28, 2026
@d99kris
Copy link
Copy Markdown
Owner

d99kris commented Mar 29, 2026

Hi @asemarafa - thanks for contributing again. 👍
Ideally I try to minimize code changes in third-party libs, like whatsmeow, but I will review the changes and see how we can proceed. Sometimes it's preferred to contribute them upstream instead.

- Request app state recovery upon LTHash mismatch in whatsmeow.
- Clear requested message IDs and refresh UI history when a chat is unarchived in uimodel.
@asemarafa asemarafa force-pushed the fix-whatsapp-archive-lthash branch from 7503585 to 24eb451 Compare April 18, 2026 21:45
@d99kris
Copy link
Copy Markdown
Owner

d99kris commented Apr 19, 2026

Hi again - I think the uimodel.cpp change makes sense, but I am a little hesitant regarding the change in whatsmeow/appstate.go. While it seems like a valid recovery method, my concern is that I have not found other whatsapp libraries doing it, and there is a potential risk of triggering possibly a large number of BuildAppStateRecoveryRequest, so we may need some throttling, or at least not perform it more than once per name, to ensure we don't exhibit some "bad client behavior" that the service may use to block users for.

Ideally I'd prefer this part of the PR to be submitted upstreams as a PR to https://github.com/tulir/whatsmeow as they may have better knowledge in assessing the correctness of the fix. And then nchat can integrate the fix once it's accepted upstream. We update the bundled whatsmeow once or twice per month. As you can see in lib/wmchat/go/ext/nchat-whatsmeow.patch the nchat deviations from upstream are quite small.

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