Blocking trait 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.jid- Contact JID to block
- 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.jid- Contact JID to unblock
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.jid- Contact JID to check
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
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
Unblock Request
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: