comparison sat/plugins/plugin_xep_0277.py @ 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 e345d93fb6e5
children b8ab6da58ac8
comparison
equal deleted inserted replaced
3948:cd4d95b3fed3 3949:f7ff893b536e
18 18
19 import time 19 import time
20 import dateutil 20 import dateutil
21 import calendar 21 import calendar
22 from secrets import token_urlsafe 22 from secrets import token_urlsafe
23 from typing import Optional, Dict, Union, Any 23 from typing import List, Optional, Dict, Tuple, Union, Any, Dict
24 from functools import partial 24 from functools import partial
25 25
26 import shortuuid 26 import shortuuid
27 27
28 from twisted.words.protocols.jabber import jid, error 28 from twisted.words.protocols.jabber import jid, error
31 from twisted.internet import defer 31 from twisted.internet import defer
32 from twisted.python import failure 32 from twisted.python import failure
33 33
34 # XXX: sat_tmp.wokkel.pubsub is actually used instead of wokkel version 34 # XXX: sat_tmp.wokkel.pubsub is actually used instead of wokkel version
35 from wokkel import pubsub 35 from wokkel import pubsub
36 from wokkel import disco, iwokkel 36 from wokkel import disco, iwokkel, rsm
37 from zope.interface import implementer 37 from zope.interface import implementer
38 38
39 from sat.core.i18n import _ 39 from sat.core.i18n import _
40 from sat.core.constants import Const as C 40 from sat.core.constants import Const as C
41 from sat.core.log import getLogger 41 from sat.core.log import getLogger
1140 extra.rsm_request, extra.extra) 1140 extra.rsm_request, extra.extra)
1141 ) 1141 )
1142 d.addCallback(self._mbGetSerialise) 1142 d.addCallback(self._mbGetSerialise)
1143 return d 1143 return d
1144 1144
1145 async def mbGet(self, client, service=None, node=None, max_items=10, item_ids=None, 1145 async def mbGet(
1146 rsm_request=None, extra=None): 1146 self,
1147 client: SatXMPPEntity,
1148 service: Optional[jid.JID] = None,
1149 node: Optional[str] = None,
1150 max_items: Optional[int] = 10,
1151 item_ids: Optional[List[str]] = None,
1152 rsm_request: Optional[rsm.RSMRequest] = None,
1153 extra: Optional[Dict[str, Any]] = None
1154 ) -> Tuple[List[Dict[str, Any]], Dict[str, Any]]:
1147 """Get some microblogs 1155 """Get some microblogs
1148 1156
1149 @param service(jid.JID, None): jid of the publisher 1157 @param service(jid.JID, None): jid of the publisher
1150 None to get profile's PEP 1158 None to get profile's PEP
1151 @param node(unicode, None): node to get (or microblog node if None) 1159 @param node(unicode, None): node to get (or microblog node if None)
1168 max_items=max_items, 1176 max_items=max_items,
1169 item_ids=item_ids, 1177 item_ids=item_ids,
1170 rsm_request=rsm_request, 1178 rsm_request=rsm_request,
1171 extra=extra, 1179 extra=extra,
1172 ) 1180 )
1173 mb_data = await self._p.transItemsDataD( 1181 mb_data_list, metadata = await self._p.transItemsDataD(
1174 items_data, partial(self.item2mbdata, client, service=service, node=node)) 1182 items_data, partial(self.item2mbdata, client, service=service, node=node))
1175 return mb_data 1183 encrypted = metadata.pop("encrypted", None)
1184 if encrypted is not None:
1185 for mb_data in mb_data_list:
1186 try:
1187 mb_data["encrypted"] = encrypted[mb_data["id"]]
1188 except KeyError:
1189 pass
1190 return (mb_data_list, metadata)
1176 1191
1177 def _mbRename(self, service, node, item_id, new_id, profile_key): 1192 def _mbRename(self, service, node, item_id, new_id, profile_key):
1178 return defer.ensureDeferred(self.mbRename( 1193 return defer.ensureDeferred(self.mbRename(
1179 self.host.getClient(profile_key), 1194 self.host.getClient(profile_key),
1180 jid.JID(service) if service else None, 1195 jid.JID(service) if service else None,