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.
jid- Contact JID to block (LID or PN)
- A LID↔PN mapping for the target must exist in the client’s mapping store. If no mapping is available, the call returns
IqError::EncodeError.
- 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)
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.jid- Contact JID to unblock (LID or PN)
get_blocklist
Retrieve the full list of blocked contacts.Vec<BlocklistEntry>- All blocked contacts
jid: Jid- Blocked contact JIDtimestamp: Option<u64>- Unix timestamp when blocked (if available)
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).jid- Contact JID to check (LID or PN)
bool-trueif blocked,falseotherwise
- 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 returnsErrrather 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.
BlocklistEntry Type
jid- The blocked contact’s JIDtimestamp- Unix timestamp (seconds since epoch) when the contact was blocked
None if the server doesn’t provide it.
Error Types
IqError
Returned byblock() and unblock() operations:
anyhow::Error
Returned byget_blocklist() and is_blocked() for general errors.
Wire Format
Block Request
The block stanza carries both the LID (injid) 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
<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
Theis_blocked() method compares only the user part of JIDs, ignoring device IDs: