slidge.contact.roster#

Module Contents#

Classes#

LegacyRoster

Virtual roster of a gateway user, that allows to represent all

exception slidge.contact.roster.ContactIsUser#

Common base class for all non-exit exceptions.

add_note()#

Exception.add_note(note) – add a note to the exception

with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class slidge.contact.roster.LegacyRoster(session)#

Virtual roster of a gateway user, that allows to represent all of their contacts as singleton instances (if used properly and not too bugged).

Every BaseSession instance will have its own LegacyRoster instance accessible via the BaseSession.contacts attribute.

Typically, you will mostly use the LegacyRoster.by_legacy_id() function to retrieve a contact instance.

You might need to override LegacyRoster.legacy_id_to_jid_username() and/or LegacyRoster.jid_username_to_legacy_id() to incorporate some custom logic if you need some characters when translation JID user parts and legacy IDs.

Parameters:

session (slidge.core.session.BaseSession) –

async by_legacy_id(legacy_id, *args, **kwargs)#

Retrieve a contact by their legacy_id

If the contact was not instantiated before, it will be created using slidge.LegacyRoster.legacy_id_to_jid_username() to infer their legacy user ID.

Parameters:
  • legacy_id (slidge.util.types.LegacyUserIdType) –

  • args – arbitrary additional positional arguments passed to the contact constructor. Requires subclassing LegacyContact.__init__ to accept those. This is useful for networks where you fetch the contact list and information about these contacts in a single request

  • kwargs – arbitrary keyword arguments passed to the contact constructor

Returns:

Return type:

slidge.util.types.LegacyContactType

async legacy_id_to_jid_username(legacy_id)#

Convert a legacy ID to a valid ‘user’ part of a JID

Should be overridden for cases where the str conversion of the legacy_id is not enough, e.g., if it is case-sensitive or contains forbidden characters not covered by XEP-0106.

Parameters:

legacy_id (slidge.util.types.LegacyUserIdType) –

Return type:

str

async jid_username_to_legacy_id(jid_username)#

Convert a JID user part to a legacy ID.

Should be overridden in case legacy IDs are not strings, or more generally for any case where the username part of a JID (unescaped with to the mapping defined by XEP-0106) is not enough to identify a contact on the legacy network.

Default implementation is an identity operation

Parameters:

jid_username (str) – User part of a JID, ie “user” in “user@example.com

Returns:

An identifier for the user on the legacy network.

Return type:

slidge.util.types.LegacyUserIdType

async fill()#

Populate slidge’s “virtual roster”.

Override this and in it, await self.by_legacy_id(contact_id) for the every legacy contacts of the user for which you’d like to set an avatar, nickname, vcard…

Await Contact.add_to_roster() in here to add the contact to the user’s XMPP roster.