Repository navigation
fix(baileys): key chat writes so the phone applies them - #1901
rjsebening wants to merge 4 commits into
Conversation
Baileys keys clear, delete, archive, mark unread and read receipts to a message of the chat, and the gateway looked that message up only in memory. The phone ignored clear and delete, and after a restart every chat without new traffic was refused (rmyndharis#1891). - Index the app-state patch and the range key by the same chat jid: a 1:1 chat by its lid whenever one is known, else its phone jid. A message keyed by its lid on a chat listed under the phone jid named two different chats, which the server accepted and the phone ignored. - Send an own group message's key without its participant; a received one keeps its sender. - Fall back to the newest message the gateway stored for the chat, across its id forms, when memory holds none (StoredChatMessageLookup, read only when the engine asks). Read receipts fall back to the newest stored received message. - With no message known at all, archive and mark unread go out without a range, which WhatsApp applies; mark unread on an archived chat and clear and delete still decline.
Keep both sides of the Unreleased Fixed section, with credit on the two entries of this branch.
|
Thanks for the thorough write-up and the phone checks. The change covers what the #1891 thread asked for: patch index and range key together, the own group key, a session-scoped fallback across id forms, archived mark unread, the refusal kept for clear and delete, and stored rows kept when an action is declined. I merged
Tests and docs:
For the record, outside this PR: The PR closes #1891 when it merges, while the local archive echo and the group-leave observation stay outside it, so those need to stay tracked. |
…y-keys # Conflicts: # CHANGELOG.md
Address the rmyndharis#1901 review: - Archive and mark unread without a range now go out only for a chat the session knows (a chat record, a persisted state row or a stored message). An unknown id answers false again: Baileys replays its own patch locally, so archiving it listed a chat the account does not have. - A stored message brings the lids the persisted mapping holds for the chat and for a group sender, so a mapping the engine's cache lacks no longer leaves the patch keyed by the phone jid. - A message held in memory is keyed under the jid it arrived with instead of a lid forced on it, so a phone-addressed chat keeps the path that worked before. - Test the stored-message query against real SQLite rows, and bring docs/07, docs/29 and the SDK markRead docs to the final behaviour.
|
Thanks for the review. I merged the latest
Tests and docs
Checks: ESLint on the changed files, Prettier, Live-checked on the same production Baileys session with this head, on a phone (iPhone):
Agreed on the points outside this PR. They stay tracked in #1891. |
|
A note on the failing Python SDK (3.9) check: |
Description
Fixes the Baileys chat writes described in #1891, scoped as discussed there. Archive, mark unread, clear, delete and read receipts are keyed to a message of the chat. Before this change, the phone ignored clear and delete, and after a restart every chat without new traffic was refused.
What changes (Baileys adapter,
BaileysContacts)<lid>@lidwhenever one is known (from the message key, the in-memory lid map or the lid mapping table), else by its phone jid. Before, a message keyed by its lid on a chat the session lists under the phone jid named two different chats. The server accepted that patch and the phone ignored it.BaileysSessionStore.lidOfexposes the lid the store already knew throughchatTwins.participant. With the account's own lid as participant, the phone ignored the clear. A received group message keeps its sender, which Baileys requires.ChatCapabilitymethods take an optionalStoredChatMessageLookup, whichSessionService.storedLastMessagebuilds. It is session-scoped and covers the chat's id forms viaresolveJidCandidates, the same rules the stored-chat purge uses. For a group it only takes a message that is own or has anauthor. The lookup runs only when the engine calls it. If it fails, the result counts as "nothing stored" and a warning is logged.messageIdsfall back to the newest received stored message the same way.success: false.Not in this PR (as requested in #1891):
Docs:
docs/06-api-specification.md(read, unread, clear, archive, delete), the route descriptions plus a regeneratedopenapi.json,engine-capability-matrix.ts, and theChatCapabilitydoc comments. The CHANGELOG has two Fixed entries.Type of Change
Checklist
baileys.adapter.spec.ts,chat writes keyed to a message (#1891)):session.service.spec.ts):eslint,prettier --check,tsc --noEmit,nest buildandnpm run openapi:checkall pass.test:docs: 7 failures, also environmental (the same two areas).Validated on a phone (iPhone) against a production Baileys session running this build, one step at a time:
For the last case, Baileys may have redelivered the message on reconnect, so that run does not isolate the stored fallback for receipts. The unit tests cover that path.
Related Issues
Refs #1891