Skip to main content
The Blocking struct provides methods for blocking and unblocking contacts, as well as retrieving and checking the blocklist.

Access

Access blocking operations through the client:

Methods

block

Block a contact. Accepts either a LID or a PN JID; the client resolves the LID↔PN pair from its mapping cache and emits a stanza carrying both (jid=LID, pn_jid=PN). Modern WhatsApp servers reject PN-only block requests.
Parameters:
  • jid - Contact JID to block (LID or PN)
Requirements:
  • A LID↔PN mapping for the target must exist in the client’s mapping store. If no mapping is available, the call returns BlockingError::InvalidJid.
Effects:
  • Contact will not be able to message you
  • Contact will not see your presence updates
  • Contact will not see your profile picture (depending on privacy settings)
Example:

unblock

Unblock a previously blocked contact. Accepts either a LID or a PN JID; PN input is internally resolved to the LID required on the wire.
Parameters:
  • jid - Contact JID to unblock (LID or PN)
Example:

get_blocklist

Retrieve the full list of blocked contacts.
Returns:
  • Vec<BlocklistEntry> - All blocked contacts
BlocklistEntry fields:
  • jid: Jid - Blocked contact JID
  • timestamp: Option<u64> - Unix timestamp when blocked (if available)
Example:

is_blocked

Check if a specific contact is blocked. Accepts either a LID or a PN JID; the client resolves the LID↔PN pair from its mapping cache so a PN-input query correctly matches a LID-keyed blocklist entry (and vice versa).
Parameters:
  • jid - Contact JID to check (LID or PN)
Returns:
  • bool - true if blocked, false otherwise
Behavior:
  • Compares only the user part of the JID (ignores device ID)
  • Blocking applies to the entire user account, not individual devices
  • Because block() stores entries keyed by LID, is_blocked() resolves the queried JID’s LID/PN pair before matching. If the mapping lookup fails (network or backend error), the call returns Err rather than silently falling back to the raw user, which would risk a false negative. When no mapping exists for the JID, the raw user part is used as-is.
Example:

BlocklistEntry Type

Fields:
  • jid - The blocked contact’s JID
  • timestamp - Unix timestamp (seconds since epoch) when the contact was blocked
The timestamp may be None if the server doesn’t provide it.

Error Types

BlockingError

All methods return Result<T, BlockingError>:
Variants:
  • Iq — Wraps an IQ request failure (timeout, server error, etc.)
  • InvalidJid — The provided JID was not a valid blocklist target
  • Internal — Internal error (network, encoding, etc.)

Wire Format

Block Request

The block stanza carries both the LID (in jid) and the PN (in pn_jid). Modern WhatsApp servers reject blocks that omit pn_jid.

Unblock Request

The unblock stanza only requires the LID; pn_jid is omitted.

Get blocklist request

Blocklist Response

Or direct items without <list> wrapper:

Usage Examples

Block a Contact

Unblock a Contact

Check before blocking

List all blocked contacts

Conditional Block/Unblock

Batch block multiple contacts

Error Handling

Device ID Handling

The is_blocked() method compares only the user part of JIDs, ignoring device IDs:

Complete Example