fix: emit labels.association remove event for tombstone mutations#2650
fix: emit labels.association remove event for tombstone mutations#2650ropic wants to merge 1 commit into
Conversation
WhatsApp sends label REMOVE operations as tombstone mutations: the mutation has operation=REMOVE but an empty labelAssociationAction field. The existing handler only checks action?.labelAssociationAction (undefined for tombstones) and falls through to "unprocessable update", so label removal events are never emitted. Two changes: 1. decodeSyncdMutations: include operation in the onMutation callback object so processSyncAction can access it. Requires adding operation as an optional field to the ChatMutation type. 2. processSyncAction: add a handler for tombstone REMOVE mutations on label_jid associations that emits labels.association with type:remove. Tested on Baileys 7.0.0-rc.9 with WhatsApp mobile (iOS/Android).
|
Thanks for opening this pull request and contributing to the project! The next step is for the maintainers to review your changes. If everything looks good, it will be approved and merged into the main branch. In the meantime, anyone in the community is encouraged to test this pull request and provide feedback. ✅ How to confirm it worksIf you’ve tested this PR, please comment below with: This helps us speed up the review and merge process. 📦 To test this PR locally:If you encounter any issues or have feedback, feel free to comment as well. |
📝 WalkthroughWalkthrough
ChangesChat-label REMOVE tombstone support
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/Utils/chat-utils.ts`:
- Around line 969-981: The tombstone REMOVE label dissociation path in the
chat-utils.ts file (where operation ===
proto.SyncdMutation.SyncdOperation.REMOVE and type ===
LabelAssociationType.Chat) currently lacks test coverage. Add a test case in
src/__tests__/Utils/process-sync-action.test.ts that exercises this specific
code path by setting up a test scenario with operation=REMOVE and
type=LabelAssociationType.Chat, then verify that the
ev.emit('labels.association', { type: 'remove', ... }) call is triggered
correctly with the appropriate ChatLabelAssociation payload.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 2911bde9-4674-4718-aba5-59b6baff955c
📒 Files selected for processing (2)
src/Types/Chat.tssrc/Utils/chat-utils.ts
| } else if ( | ||
| operation === proto.SyncdMutation.SyncdOperation.REMOVE && | ||
| type === LabelAssociationType.Chat | ||
| ) { | ||
| // Tombstone REMOVE: WhatsApp sends label removals with operation=REMOVE and empty labelAssociationAction | ||
| ev.emit('labels.association', { | ||
| type: 'remove', | ||
| association: { | ||
| type: LabelAssociationType.Chat, | ||
| chatId: msgId!, | ||
| labelId: id! | ||
| } as ChatLabelAssociation | ||
| }) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 1) Find processSyncAction tests
fd -i 'process-sync-action*.test.ts' src/__tests__ src | sed 's#^`#TEST_FILE`: #'
# 2) Search for REMOVE tombstone coverage around labels.association remove emissions
rg -n -C3 --type=ts \
"SyncdOperation\.REMOVE|labelAssociation|labels\.association|type:\s*'remove'|LabelAssociationType\.Chat" \
src/__tests__ src | sed 's#^`#MATCH`: #'Repository: WhiskeySockets/Baileys
Length of output: 13317
🏁 Script executed:
cat src/__tests__/Utils/process-sync-action.test.ts | head -300Repository: WhiskeySockets/Baileys
Length of output: 10134
🏁 Script executed:
sed -n '260,350p' src/__tests__/Utils/process-sync-action.test.tsRepository: WhiskeySockets/Baileys
Length of output: 3545
🏁 Script executed:
wc -l src/__tests__/Utils/process-sync-action.test.tsRepository: WhiskeySockets/Baileys
Length of output: 118
🏁 Script executed:
sed -n '295,359p' src/__tests__/Utils/process-sync-action.test.tsRepository: WhiskeySockets/Baileys
Length of output: 2668
Add integration test for tombstone REMOVE label dissociation
The labelAssociationAction tests cover labeled: true (ADD) cases. Add a test in src/__tests__/Utils/process-sync-action.test.ts that exercises the tombstone REMOVE path — operation === REMOVE with type === LabelAssociationType.Chat — and verifies that ev.emit('labels.association', { type: 'remove', ... }) is called correctly.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/Utils/chat-utils.ts` around lines 969 - 981, The tombstone REMOVE label
dissociation path in the chat-utils.ts file (where operation ===
proto.SyncdMutation.SyncdOperation.REMOVE and type ===
LabelAssociationType.Chat) currently lacks test coverage. Add a test case in
src/__tests__/Utils/process-sync-action.test.ts that exercises this specific
code path by setting up a test scenario with operation=REMOVE and
type=LabelAssociationType.Chat, then verify that the
ev.emit('labels.association', { type: 'remove', ... }) call is triggered
correctly with the appropriate ChatLabelAssociation payload.
Source: Coding guidelines
|
This PR is stale because it has been open for 14 days with no activity. Remove the stale label or comment or this will be closed in 14 days |
WhatsApp sends label REMOVE operations as tombstone mutations: the mutation has operation=REMOVE but an empty labelAssociationAction field. The existing handler only checks action?.labelAssociationAction (undefined for tombstones) and falls through to "unprocessable update", so label removal events are never emitted.
Two changes:
Tested on Baileys 7.0.0-rc.9 with WhatsApp mobile (iOS/Android).
Summary by cubic
Fixes missing label removal events by handling WhatsApp tombstone REMOVE mutations. Now emits
labels.associationwith type: remove when a label is removed.operationindecodeSyncdMutationsand add it toChatMutation.REMOVEonlabel_jidinprocessSyncActionand emitlabels.associationwithtype: remove.Written for commit 61b08cb. Summary will update on new commits.
Summary by CodeRabbit