feat: add identity change handler for improved connection stability
Cherry-pick from upstream PR #2264 (commit 5cbad317) with enhancements:
## Changes
### New Files
- `src/Utils/identity-change-handler.ts`: Centralized identity change handling
- Enterprise-grade JSDoc documentation
- Clear result types for all 9 possible outcomes
- Debouncing to prevent duplicate session refreshes
- Companion device filtering
- Offline notification handling
- `src/__tests__/Socket/identity-change-handling.test.ts`: Comprehensive tests
- Core functionality tests
- Debounce behavior tests
- Error handling tests
- Edge case coverage
### Modified Files
- `src/Socket/messages-recv.ts`: Updated error handling
- MISSING_KEYS_ERROR now returns NACK with ParsingError
- Maintains CTWA recovery logic intact
- Preserves all Prometheus metrics integration
- `src/Utils/generics.ts`: Added `isStringNullOrEmpty()` helper
- `src/Utils/index.ts`: Added identity-change-handler export
## Benefits
- Fixes "Online" status shown when actually disconnected (#2132)
- Better session management after contact identity changes
- Clear separation of concerns with dedicated handler module
Co-authored-by: João Lucas de Oliveira Lopes <55464917+jlucaso1@users.noreply.github.com>
This commit is contained in:
@@ -50,6 +50,10 @@ export const BufferJSON = {
|
||||
export const getKeyAuthor = (key: WAMessageKey | undefined | null, meId = 'me') =>
|
||||
(key?.fromMe ? meId : key?.participantAlt || key?.remoteJidAlt || key?.participant || key?.remoteJid) || ''
|
||||
|
||||
export const isStringNullOrEmpty = (value: string | null | undefined): value is null | undefined | '' =>
|
||||
// eslint-disable-next-line eqeqeq
|
||||
value == null || value === ''
|
||||
|
||||
export const writeRandomPadMax16 = (msg: Uint8Array) => {
|
||||
const pad = randomBytes(1)
|
||||
const padLength = (pad[0]! & 0x0f) + 1
|
||||
|
||||
Reference in New Issue
Block a user