hook.sync¶
- class immp.hook.sync.SyncBackRef(**kwargs: Any)¶
Bases:
ModelOne of a set of references, each pointing to a representation of a source message.
- async classmethod map_from_sent(sent)¶
Take a
Receiptand attempt to resolve it to a key from a previously synced reference, then defer tomap_from_key()to make the mapping with the key.
- class immp.hook.sync.SyncRef(ids, *, key=None, source=None, origin=None)¶
Bases:
objectRepresentation of a single synced message.
- source¶
Original copy of the source message, if we have it.
- Type:
.Message
- classmethod from_backref_map(key, mapped, host)¶
Take a mapping generated in
SyncBackRef.map_from_key()and produce a local reference suitable for the memory cache.
- class immp.hook.sync.SyncCache(hook)¶
Bases:
objectSynced message cache manager, using both in-memory and database-based caches.
This class has
dict-like access, using eitherReceiptobjects orSyncPlugmessage IDs that map toSyncRefkeys.- async add(ref, back=False)¶
Add a
SyncRefto the cache. This will also commit a newSyncBackRefto the database if configured.- Parameters:
ref (.SyncRef) – Newly synced message to store.
back (bool) –
Trueif sourced from aSyncBackRef, and therefore doesn’t need committing back to the database.
- Returns:
The same ref, useful for shorthand add-then-return.
- Return type:
.SyncRef
- class immp.hook.sync.SyncPlug(name, hook, host)¶
Bases:
PlugVirtual plug that allows sending external messages to a synced conversation.
- schema = None¶
- classmethod any_sync(host, channel)¶
Produce a synced channel for the given source, searching across all
SyncPluginstances running on the host.- Parameters:
host (.Host) – Controlling host instance.
channel (.Channel) – Original channel to lookup.
- Returns:
Sync channel containing the given channel as a source, or
Noneif not synced.- Return type:
.Channel
- sync_for(channel)¶
Produce a synced channel for the given source.
- Parameters:
channel (.Channel) – Original channel to lookup.
- Returns:
Sync channel containing the given channel as a source, or
Noneif not synced.- Return type:
.Channel
- in_sync(channel)¶
Retrieve the list of member channels for a given sync channel.
- Parameters:
channel (.Channel) – Virtual channel belonging to this sync instance.
- Returns:
Channels participating in this sync.
- Return type:
.Channel list
- async public_channels()¶
Retrieve all shared channels known to this plug, either public or otherwise accessible. May return
Noneif the network doesn’t support channel discovery.- Returns:
All available non-private channels.
- Return type:
.Channel list
- async private_channels()¶
Retrieve all private (one-to-one) channels known to this plug. May return
Noneif the network doesn’t support channel discovery.- Returns:
All available private channels.
- Return type:
.Channel list
- async channel_is_private(channel)¶
Test if a given channel represents a private (one-to-one) conversation between a given user and the service. May return
Noneif the network doesn’t have a notion of public/shared and private channels.- Parameters:
channel (.Channel) – Requested channel instance.
- Returns:
Trueif the channel is private.- Return type:
- async channel_title(channel)¶
Retrieve the friendly name of this channel, as used in the underlying network. May return
Noneif the service doesn’t have a notion of titles.- Returns:
Display name for the channel.
- Return type:
- async channel_members(channel)¶
Retrieve a
Userlist representing all members of the given channel. May returnNoneif the plug doesn’t recognise the channel, or is unable to query members.- Parameters:
channel (.Channel) – Requested channel instance.
- Returns:
Members present in the channel.
- Return type:
.User list
- async put(channel, msg)¶
Take a
Messageobject, and push it to the underlying network.Because some plugs may not support combinations of message components (such as text and an accompanying image), this method may send more than one physical message.
- Parameters:
channel (.Channel) – Target channel for the new message.
msg (.Message) – Original message received from another channel or plug.
- Returns:
References to new messages sent to the plug.
- Return type:
.Receipt list
- async delete(sent)¶
Request deletion of this message, if supported by the network.
- Parameters:
sent (.SentMessage) – Existing message to be removed.
- class immp.hook.sync.SyncHook(name, config, host)¶
Bases:
_SyncHookBaseHook to propagate messages between two or more channels.
- plug¶
Virtual plug for this sync, if configured.
- Type:
.SyncPlug
- on_load()¶
Perform any additional one-time setup that requires other plugs or hooks to be loaded.
- async send(label, msg, origin=None, ref=None, update=False)¶
Send a message to all channels in this synced group.
- Parameters:
label (str) – Bridge that defines the underlying synced channels to send to.
msg (.Message) – External message to push. This should be the source copy when syncing a message from another channel.
origin (.Receipt) – Raw message that triggered this sync; if set and part of the sync, it will be skipped (used to avoid retransmitting a message we just received). This should be the plug-native copy of a message when syncing from another channel.
ref (.SyncRef) – Existing sync reference, if message has been partially synced.
update (bool) –
Trueto force resending an updated message to all synced channels.
- async on_receive(sent, source, primary)¶
Handle an incoming message received by any plug.
- Parameters:
sent (.SentMessage) – Raw message received from another plug.
source (.Message) – Original message data used to generate the raw message, if sent via the plug (e.g. from another hook), equivalent to
msgif the source is otherwise unknown.primary (bool) –
Falsefor supplementary messages if the source message required multiple raw messages in order to represent it (e.g. messages with multiple attachments where the underlying network doesn’t support it), otherwiseTrue.
- class immp.hook.sync.ForwardHook(name, config, host, virtual=False)¶
Bases:
_SyncHookBaseHook to propagate messages from a source channel to one or more destination channels.
- async send(msg, channels)¶
Send a message to all channels in this forwarding group.
- Parameters:
msg (.Message) – External message to push.
channels (.Channel list) – Set of target channels to forward the message to.
- async on_receive(sent, source, primary)¶
Handle an incoming message received by any plug.
- Parameters:
sent (.SentMessage) – Raw message received from another plug.
source (.Message) – Original message data used to generate the raw message, if sent via the plug (e.g. from another hook), equivalent to
msgif the source is otherwise unknown.primary (bool) –
Falsefor supplementary messages if the source message required multiple raw messages in order to represent it (e.g. messages with multiple attachments where the underlying network doesn’t support it), otherwiseTrue.