matridge.contact

Classes

Contact

We don't implement direct messages but the what's parsed here will propagate

Roster

Virtual roster of a gateway user that allows to represent all

Module Contents

class matridge.contact.Contact(session, stored)[source]

Bases: slidge.LegacyContact[str]

We don’t implement direct messages but the what’s parsed here will propagate to MUC participants.

Parameters:
  • session (slidge.core.session.BaseSession)

  • stored (slidge.db.models.Contact)

session: matridge.session.Session[source]
async update_info()[source]

Fetch information about this contact from the legacy network

This is awaited on Contact instantiation, and should be overridden to update the nickname, avatar, vcard […] of this contact, by making “legacy API calls”.

To take advantage of the slidge avatar cache, you can check the .avatar property to retrieve the “legacy file ID” of the cached avatar. If there is no change, you should not call slidge.core.mixins.avatar.AvatarMixin.set_avatar() or attempt to modify the .avatar property.

async fetch_vcard()[source]

It the legacy network doesn’t like that you fetch too many profiles on startup, it’s also possible to fetch it here, which will be called when XMPP clients of the user request the vcard, if it hasn’t been fetched before :return:

update_presence(p)[source]
Parameters:

p (nio.PresenceEvent)

class matridge.contact.Roster(session)[source]

Bases: slidge.LegacyRoster[str, Contact]

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)

session: matridge.session.Session[source]
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.