comparison sat/plugins/plugin_xep_0060.py @ 3911:8289ac1b34f4

plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo: - support for both (modern) OMEMO under the `urn:xmpp:omemo:2` namespace and (legacy) OMEMO under the `eu.siacs.conversations.axolotl` namespace - maintains one identity across both versions of OMEMO - migrates data from the old plugin - includes more features for protocol stability - uses SCE for modern OMEMO - fully type-checked, linted and format-checked - added type hints to various pieces of backend code used by the plugin - added stubs for some Twisted APIs used by the plugin under stubs/ (use `export MYPYPATH=stubs/` before running mypy) - core (xmpp): enabled `send` trigger and made it an asyncPoint fix 375
author Syndace <me@syndace.dev>
date Tue, 23 Aug 2022 21:06:24 +0200
parents 1e64f1ed3ebd
children cecf45416403
comparison
equal deleted inserted replaced
3910:199598223f82 3911:8289ac1b34f4
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18
19 19
20 from collections import namedtuple 20 from collections import namedtuple
21 from functools import reduce 21 from functools import reduce
22 from typing import Any, Dict, List, Optional, Tuple, Union, Callable 22 from typing import Any, Dict, Iterable, List, Optional, Tuple, Union, Callable
23 import urllib.error 23 import urllib.error
24 import urllib.parse 24 import urllib.parse
25 import urllib.request 25 import urllib.request
26 26
27 from twisted.internet import defer, reactor 27 from twisted.internet import defer, reactor
37 from sat.core import exceptions 37 from sat.core import exceptions
38 from sat.core.constants import Const as C 38 from sat.core.constants import Const as C
39 from sat.core.core_types import SatXMPPEntity 39 from sat.core.core_types import SatXMPPEntity
40 from sat.core.i18n import _ 40 from sat.core.i18n import _
41 from sat.core.log import getLogger 41 from sat.core.log import getLogger
42 from sat.core.xmpp import SatXMPPClient
42 from sat.tools import utils 43 from sat.tools import utils
43 from sat.tools import sat_defer 44 from sat.tools import sat_defer
44 from sat.tools import xml_tools 45 from sat.tools import xml_tools
45 from sat.tools.common import data_format 46 from sat.tools.common import data_format
46 47
536 return defer.ensureDeferred(self.sendItems( 537 return defer.ensureDeferred(self.sendItems(
537 client, service, nodeIdentifier, items, extra=extra 538 client, service, nodeIdentifier, items, extra=extra
538 )) 539 ))
539 540
540 async def sendItem( 541 async def sendItem(
541 self, client, service, nodeIdentifier, payload, item_id=None, extra=None 542 self,
542 ): 543 client: SatXMPPClient,
544 service: Union[jid.JID, None],
545 nodeIdentifier: str,
546 payload: domish.Element,
547 item_id: Optional[str] = None,
548 extra: Optional[Dict[str, Any]] = None
549 ) -> Optional[str]:
543 """High level method to send one item 550 """High level method to send one item
544 551
545 @param service(jid.JID, None): service to send the item to 552 @param service: service to send the item to None to use PEP
546 None to use PEP 553 @param NodeIdentifier: PubSub node to use
547 @param NodeIdentifier(unicode): PubSub node to use 554 @param payload: payload of the item to send
548 @param payload(domish.Element): payload of the item to send 555 @param item_id: id to use or None to create one
549 @param item_id(unicode, None): id to use or None to create one 556 @param extra: extra options
550 @param extra(dict, None): extra option, not used yet 557 @return: id of the created item
551 @return (unicode, None): id of the created item
552 """ 558 """
553 assert isinstance(payload, domish.Element) 559 assert isinstance(payload, domish.Element)
554 item_elt = domish.Element((pubsub.NS_PUBSUB, 'item')) 560 item_elt = domish.Element((pubsub.NS_PUBSUB, 'item'))
555 if item_id is not None: 561 if item_id is not None:
556 item_elt['id'] = item_id 562 item_elt['id'] = item_id
1088 client = self.host.getClient(profile_key) 1094 client = self.host.getClient(profile_key)
1089 return self.deleteNode( 1095 return self.deleteNode(
1090 client, jid.JID(service_s) if service_s else None, nodeIdentifier 1096 client, jid.JID(service_s) if service_s else None, nodeIdentifier
1091 ) 1097 )
1092 1098
1093 def deleteNode(self, client, service, nodeIdentifier): 1099 def deleteNode(
1100 self,
1101 client: SatXMPPClient,
1102 service: jid.JID,
1103 nodeIdentifier: str
1104 ) -> defer.Deferred:
1094 return client.pubsub_client.deleteNode(service, nodeIdentifier) 1105 return client.pubsub_client.deleteNode(service, nodeIdentifier)
1095 1106
1096 def _addWatch(self, service_s, node, profile_key): 1107 def _addWatch(self, service_s, node, profile_key):
1097 """watch modifications on a node 1108 """watch modifications on a node
1098 1109
1130 notify, 1141 notify,
1131 ) 1142 )
1132 1143
1133 def retractItems( 1144 def retractItems(
1134 self, 1145 self,
1135 client, 1146 client: SatXMPPClient,
1136 service, 1147 service: jid.JID,
1137 nodeIdentifier, 1148 nodeIdentifier: str,
1138 itemIdentifiers, 1149 itemIdentifiers: Iterable[str],
1139 notify=True, 1150 notify: bool = True,
1140 ): 1151 ) -> defer.Deferred:
1141 return client.pubsub_client.retractItems( 1152 return client.pubsub_client.retractItems(
1142 service, nodeIdentifier, itemIdentifiers, notify=notify 1153 service, nodeIdentifier, itemIdentifiers, notify=notify
1143 ) 1154 )
1144 1155
1145 def _renameItem( 1156 def _renameItem(