changeset 3949:f7ff893b536e

plugin XEP-0277: add `encryption` flag to MB data: MB data are individually flagged with the new `encryption` key if they were e2ee, the key contain encryption metadata (for now, just the algorithm used). rel 380
author Goffi <goffi@goffi.org>
date Sat, 15 Oct 2022 20:38:33 +0200
parents cd4d95b3fed3
children 8f87ff449a34
files sat/plugins/plugin_xep_0277.py
diffstat 1 files changed, 21 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0277.py	Sat Oct 15 20:38:33 2022 +0200
+++ b/sat/plugins/plugin_xep_0277.py	Sat Oct 15 20:38:33 2022 +0200
@@ -20,7 +20,7 @@
 import dateutil
 import calendar
 from secrets import token_urlsafe
-from typing import Optional, Dict, Union, Any
+from typing import List, Optional, Dict, Tuple, Union, Any, Dict
 from functools import partial
 
 import shortuuid
@@ -33,7 +33,7 @@
 
 # XXX: sat_tmp.wokkel.pubsub is actually used instead of wokkel version
 from wokkel import pubsub
-from wokkel import disco, iwokkel
+from wokkel import disco, iwokkel, rsm
 from zope.interface import implementer
 
 from sat.core.i18n import _
@@ -1142,8 +1142,16 @@
         d.addCallback(self._mbGetSerialise)
         return d
 
-    async def mbGet(self, client, service=None, node=None, max_items=10, item_ids=None,
-              rsm_request=None, extra=None):
+    async def mbGet(
+        self,
+        client: SatXMPPEntity,
+        service: Optional[jid.JID] = None,
+        node: Optional[str] = None,
+        max_items: Optional[int] = 10,
+        item_ids: Optional[List[str]] = None,
+        rsm_request: Optional[rsm.RSMRequest] = None,
+        extra: Optional[Dict[str, Any]] = None
+    ) -> Tuple[List[Dict[str, Any]], Dict[str, Any]]:
         """Get some microblogs
 
         @param service(jid.JID, None): jid of the publisher
@@ -1170,9 +1178,16 @@
             rsm_request=rsm_request,
             extra=extra,
         )
-        mb_data = await self._p.transItemsDataD(
+        mb_data_list, metadata = await self._p.transItemsDataD(
             items_data, partial(self.item2mbdata, client, service=service, node=node))
-        return mb_data
+        encrypted = metadata.pop("encrypted", None)
+        if encrypted is not None:
+            for mb_data in mb_data_list:
+                try:
+                    mb_data["encrypted"] = encrypted[mb_data["id"]]
+                except KeyError:
+                    pass
+        return (mb_data_list, metadata)
 
     def _mbRename(self, service, node, item_id, new_id, profile_key):
         return defer.ensureDeferred(self.mbRename(