plugin XEP-0384: fix trigger used for OLDMEMO:
OLDMEMO was applied at the `send_message_data` trigger level, however this was missing stanza constructed without message data (which is notably the case for XEP-0308). This has been fixed by using the `send` trigger instead. As a side effect, the same code is now used for TWOMEMO and OLDMEMO, making it simpler.
This commit is contained in:
parent
85cecd3d30
commit
67e8367ff3
1 changed files with 13 additions and 54 deletions
|
|
@ -1584,13 +1584,7 @@ class OMEMO:
|
|||
self._message_received_trigger,
|
||||
priority=100050
|
||||
)
|
||||
sat.trigger.add(
|
||||
"send_message_data",
|
||||
self.__send_message_data_trigger,
|
||||
priority=100050
|
||||
)
|
||||
|
||||
# These triggers are used by twomemo, which does do SCE
|
||||
sat.trigger.add("send", self.__send_trigger, priority=0)
|
||||
# TODO: Add new triggers here for freshly received and about-to-be-sent stanzas,
|
||||
# including IQs.
|
||||
|
|
@ -2418,19 +2412,22 @@ class OMEMO:
|
|||
# Encryption is not requested for this recipient
|
||||
return True
|
||||
|
||||
if encryption["plugin"].namespace != twomemo.twomemo.NAMESPACE:
|
||||
encryption_ns = encryption["plugin"].namespace
|
||||
# All pre-checks done, we can start encrypting!
|
||||
if encryption_ns in (twomemo.twomemo.NAMESPACE, oldmemo.oldmemo.NAMESPACE):
|
||||
await self.encrypt(
|
||||
client,
|
||||
encryption_ns,
|
||||
stanza,
|
||||
recipient_bare_jid,
|
||||
stanza.getAttribute("type", C.MESS_TYPE_NORMAL) == C.MESS_TYPE_GROUPCHAT,
|
||||
stanza.getAttribute("id", None)
|
||||
)
|
||||
else:
|
||||
# Encryption is requested for this recipient, but not with twomemo
|
||||
return True
|
||||
|
||||
# All pre-checks done, we can start encrypting!
|
||||
await self.encrypt(
|
||||
client,
|
||||
twomemo.twomemo.NAMESPACE,
|
||||
stanza,
|
||||
recipient_bare_jid,
|
||||
stanza.getAttribute("type", C.MESS_TYPE_NORMAL) == C.MESS_TYPE_GROUPCHAT,
|
||||
stanza.getAttribute("id", None)
|
||||
)
|
||||
|
||||
|
||||
# Add a store hint if this is a message stanza
|
||||
if stanza.name == "message":
|
||||
|
|
@ -2439,44 +2436,6 @@ class OMEMO:
|
|||
# Let the flow continue.
|
||||
return True
|
||||
|
||||
async def __send_message_data_trigger(
|
||||
self,
|
||||
client: SatXMPPClient,
|
||||
mess_data: MessageData
|
||||
) -> None:
|
||||
"""
|
||||
@param client: The client sending this message.
|
||||
@param mess_data: The message data that is about to be sent. Can be modified.
|
||||
"""
|
||||
|
||||
# Check whether encryption is requested for this message
|
||||
try:
|
||||
namespace = mess_data[C.MESS_KEY_ENCRYPTION]["plugin"].namespace
|
||||
except KeyError:
|
||||
return
|
||||
|
||||
# If encryption is requested, check whether it's oldmemo
|
||||
if namespace != oldmemo.oldmemo.NAMESPACE:
|
||||
return
|
||||
|
||||
# All pre-checks done, we can start encrypting!
|
||||
stanza = mess_data["xml"]
|
||||
recipient_jid = mess_data["to"]
|
||||
is_muc_message = mess_data["type"] == C.MESS_TYPE_GROUPCHAT
|
||||
stanza_id = mess_data["uid"]
|
||||
|
||||
await self.encrypt(
|
||||
client,
|
||||
oldmemo.oldmemo.NAMESPACE,
|
||||
stanza,
|
||||
recipient_jid,
|
||||
is_muc_message,
|
||||
stanza_id
|
||||
)
|
||||
|
||||
# Add a store hint
|
||||
self.__xep_0334.add_hint_elements(stanza, [ "store" ])
|
||||
|
||||
async def encrypt(
|
||||
self,
|
||||
client: SatXMPPClient,
|
||||
|
|
|
|||
Loading…
Reference in a new issue