matteridge.session

Module Contents

Classes

Session

The session of a registered User.

Functions

Attributes

matteridge.session.Recipient[source]
matteridge.session.P[source]
matteridge.session.T[source]
matteridge.session.lock(meth)[source]
Parameters:

meth (Callable[Concatenate[Session, P], T])

Return type:

Callable[Concatenate[Session, P], T]

matteridge.session.catch_expired_session(meth)[source]
Parameters:

meth (Callable[Concatenate[Session, P], T])

Return type:

Callable[Concatenate[Session, P], T]

class matteridge.session.Session(user)[source]

Bases: slidge.BaseSession[str, Recipient]

The session of a registered User.

Represents a gateway user logged in to the legacy network and performing actions.

Will be instantiated automatically on slidge startup for each registered user, or upon registration for new (validated) users.

Must be subclassed for a functional Legacy Module.

contacts: matteridge.contact.Roster[source]
bookmarks: matteridge.group.Bookmarks[source]
MESSAGE_IDS_ARE_THREAD_IDS = True[source]
xmpp: matteridge.gateway.Gateway[source]
__init_ws()[source]
async is_waiting_for_echo(post_id)[source]
Parameters:

post_id (str)

async is_reaction_waiting_for_echo(post_id, emoji, add)[source]
Parameters:
async renew_token()[source]
Return type:

bool

update_token(token)[source]
Parameters:

token (str)

async login()[source]

Logs in the gateway user to the legacy network.

Triggered when the gateway start and on user registration. It is recommended that this function returns once the user is logged in, so if you need to await forever (for instance to listen to incoming events), it’s a good idea to wrap your listener in an asyncio.Task.

Returns:

Optionally, a text to use as the gateway status, e.g., “Connected as ‘dude@legacy.network’”

_connection_fail(task)[source]
Parameters:

task (asyncio.Task)

async __get_contact_or_participant(user_id, channel_id)[source]
Parameters:
  • user_id (str)

  • channel_id (str)

async on_mm_event(event)[source]
Parameters:

event (matteridge.events.MattermostEvent)

async on_mm_DirectAdded(event)[source]
Parameters:

event (matteridge.events.DirectAdded)

async on_mm_Posted(event)[source]
Parameters:

event (matteridge.events.Posted)

async on_mm_ChannelViewed(event)[source]
Parameters:

event (matteridge.events.ChannelViewed)

async on_mm_StatusChange(event)[source]
Parameters:

event (matteridge.events.StatusChange)

async on_mm_Typing(event)[source]
Parameters:

event (matteridge.events.Typing)

async on_mm_PostEdited(event)[source]
Parameters:

event (matteridge.events.PostEdited)

async on_mm_PostDeleted(event)[source]
Parameters:

event (matteridge.events.PostDeleted)

async on_mm_ChannelCreated(event)[source]
Parameters:

event (matteridge.events.ChannelCreated)

async on_mm_ReactionAdded(event)[source]
Parameters:

event (matteridge.events.ReactionAdded)

async on_mm_ReactionRemoved(event)[source]
Parameters:

event (matteridge.events.ReactionRemoved)

async on_mm_reaction(event)[source]
Parameters:

event (Union[matteridge.events.ReactionAdded, matteridge.events.ReactionRemoved])

async on_mm_UserUpdated(event)[source]
Parameters:

event (matteridge.events.UserUpdated)

async on_mm_UserAdded(event)[source]
Parameters:

event (matteridge.events.UserAdded)

async logout()[source]

Logs out the gateway user from the legacy network.

Called on gateway shutdown.

async static __get_channel_id(chat)[source]
Parameters:

chat (Recipient)

async on_text(chat, text, thread=None, **k)[source]

Triggered when the user sends a text message from XMPP to a bridged entity, e.g. to translated_user_name@slidge.example.com, or translated_group_name@slidge.example.com

Override this and implement sending a message to the legacy network in this method.

Parameters:
  • text (str) – Content of the message

  • chat (Recipient) – Recipient of the message. LegacyContact instance for 1:1 chat, MUC instance for groups.

  • reply_to_msg_id – A legacy message ID if the message references (quotes) another message (XEP-0461)

  • reply_to_fallback_text – Content of the quoted text. Not necessarily set by XMPP clients

  • reply_to – Author of the quoted message. LegacyContact instance for 1:1 chat, LegacyParticipant instance for groups. If None, should be interpreted as a self-reply if reply_to_msg_id is not None.

  • link_previews – A list of sender-generated link previews. At the time of writing, only Cheogram supports it.

  • mentions – (only for groups) A list of Contacts mentioned by their nicknames.

  • thread

Returns:

An ID of some sort that can be used later to ack and mark the message as read by the user

async on_file(chat, url, http_response, thread=None, **k)[source]

Triggered when the user sends a file using HTTP Upload (XEP-0363)

Parameters:
  • url (str) – URL of the file

  • chat (Recipient) – See BaseSession.on_text()

  • http_response – The HTTP GET response object on the URL

  • reply_to_msg_id – See BaseSession.on_text()

  • reply_to_fallback_text – See BaseSession.on_text()

  • reply_to – See BaseSession.on_text()

  • thread

Returns:

An ID of some sort that can be used later to ack and mark the message as read by the user

async on_active(c, thread=None)[source]

Triggered when the user sends an ‘active’ chat state (XEP-0085)

Parameters:
  • chat – See BaseSession.on_text()

  • thread

  • c (Recipient)

async on_inactive(c, thread=None)[source]

Triggered when the user sends an ‘inactive’ chat state (XEP-0085)

Parameters:
  • chat – See BaseSession.on_text()

  • thread

  • c (Recipient)

async on_composing(c, thread=None)[source]

Triggered when the user starts typing in a legacy chat (XEP-0085)

Parameters:
  • chat – See BaseSession.on_text()

  • thread

  • c (Recipient)

async on_paused(c, thread=None)[source]

Triggered when the user pauses typing in a legacy chat (XEP-0085)

Parameters:
  • chat – See BaseSession.on_text()

  • thread

  • c (Recipient)

async on_displayed(c, legacy_msg_id, thread=None)[source]

Triggered when the user reads a message in a legacy chat. (XEP-0333)

This is only possible if a valid legacy_msg_id was passed when transmitting a message from a legacy chat to the user, eg in slidge.contact.LegacyContact.send_text() or slidge.group.LegacyParticipant.send_text().

Parameters:
  • chat – See BaseSession.on_text()

  • legacy_msg_id (Any) – Identifier of the message/

  • thread

  • c (Recipient)

async on_correct(c, text, legacy_msg_id, thread=None, link_previews=(), mentions=None)[source]

Triggered when the user corrects a message using XEP-0308

This is only possible if a valid legacy_msg_id was returned by on_text().

Parameters:
  • chat – See BaseSession.on_text()

  • text (str) – The new text

  • legacy_msg_id (str) – Identifier of the edited message

  • thread

  • link_previews

    A list of sender-generated link previews. At the time of writing, only Cheogram supports it.

  • mentions – (only for groups) A list of Contacts mentioned by their nicknames.

  • c (Recipient)

Triggered when the user uses Jabber Search (XEP-0055) on the component

Form values is a dict in which keys are defined in BaseGateway.SEARCH_FIELDS

Parameters:

form_values (dict[str, str]) – search query, defined for a specific plugin by overriding in BaseGateway.SEARCH_FIELDS

Returns:

async on_retract(c, legacy_msg_id, thread=None)[source]

Triggered when the user retracts (XEP-0424) a message.

Parameters:
  • chat – See BaseSession.on_text()

  • thread

  • legacy_msg_id (Any) – Legacy ID of the retracted message

  • c (Recipient)

async on_react(c, legacy_msg_id, emojis, thread=None)[source]

Triggered when the user sends message reactions (XEP-0444).

Parameters:
  • chat – See BaseSession.on_text()

  • thread

  • legacy_msg_id (Any) – ID of the message the user reacts to

  • emojis (list[str]) – Unicode characters representing reactions to the message legacy_msg_id. An empty string means “no reaction”, ie, remove all reactions if any were present before

  • c (Recipient)

async get_mm_reactions(legacy_msg_id, user_id)[source]
Parameters:
  • legacy_msg_id (str)

  • user_id (Optional[str])

async on_presence(resource, show, status, resources, merged_resource)[source]

Called when the gateway component receives a presence, ie, when one of the user’s clients goes online of offline, or changes its status.

Parameters:
  • resource (str) – The XMPP client identifier, arbitrary string.

  • show (slidge.util.types.PseudoPresenceShow) – The presence <show>, if available. If the resource is just ‘available’ without any <show> element, this is an empty str.

  • status (str) – A status message, like a deeply profound quote, eg, “Roses are red, violets are blue, [INSERT JOKE]”.

  • resources (dict[str, slidge.util.types.ResourceDict]) – A summary of all the resources for this user.

  • merged_resource (Optional[slidge.util.types.ResourceDict]) – A global presence for the user account, following rules described in merge_resources()