Mercurial > libervia-backend
changeset 4164:15482dc0b5d1
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.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 28 Nov 2023 17:41:02 +0100 |
parents | 3b3cd9453d9b |
children | 81faa85c9cfa |
files | libervia/backend/plugins/plugin_xep_0384.py |
diffstat | 1 files changed, 14 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/libervia/backend/plugins/plugin_xep_0384.py Tue Nov 28 17:38:31 2023 +0100 +++ b/libervia/backend/plugins/plugin_xep_0384.py Tue Nov 28 17:41:02 2023 +0100 @@ -1584,13 +1584,7 @@ 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 @@ # 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 @@ # 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,