plugin XEP-0131: update triggers priority + add headers to MessageDataExtra:
- Lower priority is used for triggers so other plugins can add headers before the XML is generated. - Added `headers` to `MessageDataExtra` type. rel 456
This commit is contained in:
parent
55e4d0bc48
commit
5681435532
3 changed files with 14 additions and 10 deletions
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
from abc import ABC, abstractmethod
|
||||
from collections import namedtuple
|
||||
from typing import Dict, Callable, Optional
|
||||
from typing import Any
|
||||
from twisted.internet import defer
|
||||
from twisted.python import failure
|
||||
from typing_extensions import TypedDict
|
||||
|
|
@ -42,7 +42,7 @@ class EncryptionSession(TypedDict):
|
|||
|
||||
# Incomplete types built through observation rather than code inspection.
|
||||
MessageDataExtra = TypedDict(
|
||||
"MessageDataExtra", {"encrypted": bool, "origin_id": str}, total=False
|
||||
"MessageDataExtra", {"encrypted": bool, "origin_id": str, "headers": dict[str, Any]}, total=False
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -52,8 +52,8 @@ MessageData = TypedDict(
|
|||
"from": t_jid.JID,
|
||||
"to": t_jid.JID,
|
||||
"uid": str,
|
||||
"message": Dict[str, str],
|
||||
"subject": Dict[str, str],
|
||||
"message": dict[str, str],
|
||||
"subject": dict[str, str],
|
||||
"type": str,
|
||||
"timestamp": float,
|
||||
"extra": MessageDataExtra,
|
||||
|
|
@ -129,7 +129,7 @@ class SatXMPPEntity(ABC):
|
|||
def generate_message_xml(
|
||||
self,
|
||||
data: MessageData,
|
||||
post_xml_treatments: Optional[defer.Deferred] = None,
|
||||
post_xml_treatments: defer.Deferred|None = None,
|
||||
) -> MessageData:
|
||||
"""Generate <message/> stanza from message data
|
||||
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ class Discovery(object):
|
|||
@param category: identity category
|
||||
@param type_: identity type
|
||||
@param jid_: jid of the target, or None for profile's server
|
||||
@param node(unicode): optional node to use for disco request
|
||||
@param node: optional node to use for disco request
|
||||
@return: True if the entity has the given identity
|
||||
"""
|
||||
disco_infos = await self.get_infos(client, jid_, node)
|
||||
|
|
|
|||
|
|
@ -151,9 +151,13 @@ class XEP_0131:
|
|||
log.info(_("Stanza Headers and Internet Metadata plugin initialization"))
|
||||
self.host = host
|
||||
host.register_namespace("shim", NS_SHIM)
|
||||
host.trigger.add("sendMessage", self.send_message_trigger)
|
||||
host.trigger.add("sendMessageComponent", self.send_message_trigger)
|
||||
host.trigger.add("message_received", self.message_received_trigger)
|
||||
# We give negative priority, as we want header to be added after normal priority
|
||||
# trigger are called, in case they add their own headers.
|
||||
host.trigger.add("sendMessage", self.send_message_trigger, priority=-50)
|
||||
host.trigger.add("sendMessageComponent", self.send_message_trigger, priority=-50)
|
||||
# We give non defaut priority, has we want header parsing to be done before normal
|
||||
# priority triggers are called.
|
||||
host.trigger.add("message_received", self.message_received_trigger, priority=50)
|
||||
|
||||
def quote_value(self, value: str) -> str:
|
||||
"""Quote a value if it contain special characters
|
||||
|
|
@ -241,7 +245,7 @@ class XEP_0131:
|
|||
pass
|
||||
else:
|
||||
|
||||
def post_treat_addr(mess_data: MessageData):
|
||||
def post_treat_addr(mess_data: MessageData) -> MessageData:
|
||||
"""Add the headers metadata to the message data"""
|
||||
if headers.keywords:
|
||||
# We move keywords to a list of string in extra's "keywords" field.
|
||||
|
|
|
|||
Loading…
Reference in a new issue