changeset 3228:cc3fea71c365

core (memory/encryption): set encrypted flag also for outgoing messages and put it in extra: - `encrypted` flag is now put directly in extra, so that there is nothing to change when sending the message to bridge for frontends to be aware of it. - this flag is now also set when markAsEncrypted is used, so frontend can display appropriate indicator to show that outgoing message is encrypted or not.
author Goffi <goffi@goffi.org>
date Mon, 23 Mar 2020 16:53:03 +0100
parents 6d19a99172d7
children 2556eb576aed
files sat/core/xmpp.py sat/memory/encryption.py
diffstat 2 files changed, 6 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/sat/core/xmpp.py	Sun Mar 22 18:47:59 2020 +0100
+++ b/sat/core/xmpp.py	Mon Mar 23 16:53:03 2020 +0100
@@ -1183,8 +1183,8 @@
             data["extra"]["delay_sender"] = data["delay_sender"]
         except KeyError:
             pass
-        if C.MESS_KEY_ENCRYPTION in data:
-            data["extra"]["encrypted"] = C.BOOL_TRUE
+        if self.client.encryption.isEncrypted(data):
+            data["extra"]["encrypted"] = True
         if data is not None:
             if self.parent.isMessagePrintable(data):
                 self.host.bridge.messageNew(
--- a/sat/memory/encryption.py	Sun Mar 22 18:47:59 2020 +0100
+++ b/sat/memory/encryption.py	Mon Mar 23 16:53:03 2020 +0100
@@ -447,6 +447,7 @@
                 f"encryption flag must not be set for groupchat if encryption algorithm "
                 f"({encryption['plugin'].name}) is directed!")
             mess_data[C.MESS_KEY_ENCRYPTION] = encryption
+            self.markAsEncrypted(mess_data)
 
     ## Misc ##
 
@@ -457,7 +458,7 @@
         the plugin
         @param mess_data(dict): message data as used in post treat workflow
         """
-        mess_data[C.MESS_KEY_ENCRYPTED] = True
+        mess_data['extra'][C.MESS_KEY_ENCRYPTED] = True
         return mess_data
 
     def isEncryptionRequested(self, mess_data, namespace=None):
@@ -478,12 +479,12 @@
         return plugin.namespace == namespace
 
     def isEncrypted(self, mess_data):
-        """Helper method to check if an incoming message has the e2e encrypted flag
+        """Helper method to check if a message has the e2e encrypted flag
 
         @param mess_data(dict): message data
         @return (bool): True if the encrypted flag is present
         """
-        return mess_data.get(C.MESS_KEY_ENCRYPTED, False)
+        return mess_data['extra'].get(C.MESS_KEY_ENCRYPTED, False)
 
 
     def markAsTrusted(self, mess_data):