slidge.core.contact.roster
#
Module Contents#
Classes#
Virtual roster of a gateway user, that allows to represent all |
Attributes#
- exception slidge.core.contact.roster.ContactIsUser[source]#
Bases:
Exception
Common base class for all non-exit exceptions.
Initialize self. See help(type(self)) for accurate signature.
- class slidge.core.contact.roster.LegacyRoster(session)[source]#
Bases:
Generic
[slidge.util.types.LegacyUserIdType
,slidge.util.types.LegacyContactType
],slidge.core.mixins.lock.NamedLockMixin
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 ownLegacyRoster
instance accessible via theBaseSession.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/orLegacyRoster.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 __finish_init_contact(legacy_id, jid_username, *args, **kwargs)[source]#
- Parameters:
legacy_id (slidge.util.types.LegacyUserIdType) –
jid_username (str) –
- async by_jid(contact_jid)[source]#
Retrieve a contact by their JID
If the contact was not instantiated before, it will be created using
slidge.LegacyRoster.jid_username_to_legacy_id()
to infer their legacy user ID.- Parameters:
contact_jid (slixmpp.JID) –
- Returns:
- Return type:
slidge.util.types.LegacyContactType
- async by_legacy_id(legacy_id, *args, **kwargs)[source]#
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 by_stanza(s)[source]#
Retrieve a contact by the destination of a stanza
See
slidge.Roster.by_legacy_id()
for more info.- Parameters:
s –
- Returns:
- Return type:
- async legacy_id_to_jid_username(legacy_id)[source]#
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:
- async jid_username_to_legacy_id(jid_username)[source]#
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()[source]#
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.