slidge.space

Managing Spaces XEP-0503

Spaces are a collection of rooms.

Package Contents

class slidge.space.LegacySpaceNodes[SpaceT: slidge.space.space.LegacySpace](session: slidge.util.types.AnySession)

A class to manage XEP-0503 spaces.

It is accessible through the .spaces attribute of the slidge.BaseSession of a given user.

get(legacy_id: str) → ChildT | None

Get a Contact or Room that has been created before.

async create(legacy_id: str) → ChildT

Create a new Contact, Space or Space.

This must raise if legacy id does not map to something existing.

A typical pattern is to have a method constructing a Contact or a Room from a “metadata struct” provided by the legacy network, in the spirit of:

class LegacyRoster[Contact]:
    def create(self, legacy_id: str) -> Contact:
        meta = self._session.legacy_client.fetch_contact(legacy_id)
        if meta is None:
            raise XMPPError("item-not-found", f"No contact {legacy_id!r}")
        return await self.get_or_create_by_meta(meta)

    def get_or_create_by_meta(self, meta: legacy_lib.ContactMetadata) -> Contact:
        contact = self.get(meta.id) or self._create(legacy_id)
        contact.set_meta(meta)
        return contact
async get_or_create(legacy_id: str, *args: object) → ChildT

Get an existing Recipient or Space or create() it if does not exist.

Parameters:
  • legacy_id – The unique ID of this Contact

  • *args –

    Optionally, arguments passed to create(). Make sure that these match whatever your create() override expects. NB: nothing is passed to get().

async fill() → collections.abc.AsyncIterator[ChildT]

This is called once on startup, and should yield recipients with updated metadata.

class slidge.space.LegacySpace[T: slidge.util.types.ExtraAttrMapping](session: slidge.util.types.AnySession, *, stored: slidge.db.models.Space)

A XEP-0503 space.

property banner: slidge.util.types.Avatar | None

This property can be used to set or unset the banner.

property avatar: slidge.util.types.Avatar | None

This property can be used to set or unset the avatar.