slidge_whatsapp.group#

Module Contents#

Classes#

Participant

A legacy participant of a legacy group chat.

MUC

A room, a.k.a. a Multi-User Chat.

Bookmarks

This is instantiated once per BaseSession

Functions#

replace_xmpp_mentions(text, mentions)

replace_whatsapp_mentions(text, participants)

class slidge_whatsapp.group.Participant(muc, nickname=None, is_user=False, is_system=False, role='participant', affiliation='member')[source]#

Bases: slidge.group.LegacyParticipant

A legacy participant of a legacy group chat.

Parameters:
  • muc (slidge.group.room.LegacyMUC) –

  • nickname (Optional[str]) –

  • role (slidge.util.types.MucRole) –

  • affiliation (slidge.util.types.MucAffiliation) –

contact: slidge_whatsapp.contact.Contact[source]#
muc: MUC[source]#
send_text(body, legacy_msg_id, **kw)[source]#

Send a text message from this XMPP Entity.

Parameters:
  • body – Content of the message

  • legacy_msg_id – If you want to be able to transport read markers from the gateway user to the legacy network, specify this

  • when – when the message was sent, for a “delay” tag (XEP-0203)

  • reply_to – Quote another message (XEP-0461)

  • hints

  • thread

  • carbon – (only used if called on a LegacyContact) Set this to True if this is actually a message sent to the LegacyContact by the User. Use this to synchronize outgoing history for legacy official apps.

  • correction – whether this message is a correction or not

  • correction_event_id – in the case where an ID is associated with the legacy ‘correction event’, specify it here to use it on the XMPP side. If not specified, a random ID will be used.

  • link_previews – A little of sender (or server, or gateway)-generated previews of URLs linked in the body.

  • archive_only – (only in groups) Do not send this message to user, but store it in the archive. Meant to be used during MUC.backfill()

async send_file(file_path, legacy_msg_id, **kw)[source]#

Send a single file from this XMPP Entity.

Parameters:
  • file_path – Path to the attachment

  • data_stream – Alternatively, a stream of bytes (such as a File object)

  • data – Alternatively, a bytes object

  • file_url – Alternatively, a URL

  • file_name – How the file should be named.

  • content_type – MIME type, inferred from filename if not given

  • legacy_msg_id – If you want to be able to transport read markers from the gateway user to the legacy network, specify this

  • reply_to – Quote another message (XEP-0461)

  • when – when the file was sent, for a “delay” tag (XEP-0203)

  • caption – an optional text that is linked to the file

  • legacy_file_id – A unique identifier for the file on the legacy network. Plugins should try their best to provide it, to avoid duplicates.

  • thread

_store(legacy_msg_id)[source]#
Parameters:

legacy_msg_id (str) –

class slidge_whatsapp.group.MUC(*a, **kw)[source]#

Bases: slidge.group.LegacyMUC[str, str, Participant, str]

A room, a.k.a. a Multi-User Chat.

MUC instances are obtained by calling slidge.group.bookmarks.LegacyBookmarks() on the user’s slidge.core.session.BaseSession.

session: slidge_whatsapp.session.Session[source]#
type[source]#
REACTIONS_SINGLE_EMOJI = True[source]#
_ALL_INFO_FILLED_ON_STARTUP = True[source]#
HAS_DESCRIPTION = False[source]#
async update_info()[source]#

Fetch information about this group from the legacy network

This is awaited on MUC instantiation, and should be overridden to update the attributes of the group chat, like title, subject, number of participants etc.

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 :attr:.avatar property.

async backfill(oldest_message_id=None, oldest_message_date=None)[source]#

Request history for messages older than the oldest message given by ID and date.

Parameters:
get_message_sender(legacy_msg_id)[source]#
Parameters:

legacy_msg_id (str) –

async update_whatsapp_info(info)[source]#

Set MUC information based on WhatsApp group information, which may or may not be partial in case of updates to existing MUCs.

Parameters:

info (slidge_whatsapp.generated.whatsapp.Group) –

replace_mentions(t)[source]#
Parameters:

t (str) –

async on_avatar(data, mime)[source]#

Called when the user tries to set the avatar of the room from an XMPP client.

If the set avatar operation is completed, should return a legacy image unique identifier. In this case the MUC avatar will be immediately updated on the XMPP side.

If data is not None and this method returns None, then we assume that self.set_avatar() will be called elsewhere, eg triggered by a legacy room update event.

Parameters:
  • data (Optional[bytes]) – image data or None if the user meant to remove the avatar

  • mime (Optional[str]) – the mime type of the image. Since this is provided by the XMPP client, there is no guarantee that this is valid or correct.

Returns:

A unique avatar identifier, which will trigger slidge.group.room.LegacyMUC.set_avatar(). Alternatively, None, if LegacyMUC.set_avatar() is meant to be awaited somewhere else.

Return type:

None

async on_set_config(name, description)[source]#

Triggered when the user requests changing the room configuration. Only title and description can be changed at the moment.

The legacy module is responsible for updating title and/or description of this instance.

If HAS_DESCRIPTION is set to False, description will always be None.

Parameters:
  • name (Optional[str]) – The new name of the room.

  • description (Optional[str]) – The new description of the room.

async on_set_subject(subject)[source]#

Triggered when the user requests changing the room subject.

The legacy module is responsible for updating subject of this instance.

Parameters:

subject (str) – The new subject for this room.

async on_set_affiliation(contact, affiliation, reason, nickname)[source]#

Triggered when the user requests changing the affiliation of a contact for this group,

Examples: promotion them to moderator, kick (affiliation=none), ban (affiliation=outcast).

Parameters:
  • contact (slidge_whatsapp.contact.Contact) – The contact whose affiliation change is requested

  • affiliation (slidge.util.types.MucAffiliation) – The new affiliation

  • reason (Optional[str]) – A reason for this affiliation change

  • nickname (Optional[str]) –

class slidge_whatsapp.group.Bookmarks(session)[source]#

Bases: slidge.group.LegacyBookmarks[str, MUC]

This is instantiated once per BaseSession

Parameters:

session (slidge_whatsapp.session.Session) –

session: slidge_whatsapp.session.Session[source]#
async fill()[source]#

Establish a user’s known groups.

This has to be overridden in plugins with group support and at the minimum, this should await self.by_legacy_id(group_id) for all the groups a user is part of.

Slidge internals will call this on successful BaseSession.login()

async add_whatsapp_group(data)[source]#
Parameters:

data (slidge_whatsapp.generated.whatsapp.Group) –

async legacy_id_to_jid_local_part(legacy_id)[source]#
Parameters:

legacy_id (str) –

async jid_local_part_to_legacy_id(local_part)[source]#
Parameters:

local_part (str) –

slidge_whatsapp.group.replace_xmpp_mentions(text, mentions)[source]#
Parameters:
  • text (str) –

  • mentions (list[slidge.util.types.Mention]) –

slidge_whatsapp.group.replace_whatsapp_mentions(text, participants)[source]#
Parameters: