comparison sat/plugins/plugin_comp_ap_gateway/__init__.py @ 3824:6329ee6b6df4

component AP: convert AP identity data to XMPP: metadata are converted to vCard4 (XEP-0292). Avatar is converted to User Avatar (XEP-0084), it is downloaded, resized, converted and cached on first request. If avatar is bigger than 5 Mio, it won't be used. rel 368
author Goffi <goffi@goffi.org>
date Wed, 29 Jun 2022 12:12:09 +0200
parents 0b1c30ff2cbb
children 201a22bfbb74
comparison
equal deleted inserted replaced
3823:5d72dc52ee4a 3824:6329ee6b6df4
48 from sat.core.constants import Const as C 48 from sat.core.constants import Const as C
49 from sat.core.core_types import SatXMPPEntity 49 from sat.core.core_types import SatXMPPEntity
50 from sat.core.i18n import _ 50 from sat.core.i18n import _
51 from sat.core.log import getLogger 51 from sat.core.log import getLogger
52 from sat.memory.sqla_mapping import SubscriptionState, History 52 from sat.memory.sqla_mapping import SubscriptionState, History
53 from sat.memory import persistent
53 from sat.tools import utils 54 from sat.tools import utils
54 from sat.tools.common import data_format, tls, uri 55 from sat.tools.common import data_format, tls, uri
55 from sat.tools.common.async_utils import async_lru 56 from sat.tools.common.async_utils import async_lru
56 57
57 from .constants import ( 58 from .constants import (
103 RE_PERCENT_ENC = re.compile(f"%{HEXA_ENC}") 104 RE_PERCENT_ENC = re.compile(f"%{HEXA_ENC}")
104 RE_ALLOWED_UNQUOTED = re.compile(r"^[a-zA-Z0-9_-]+$") 105 RE_ALLOWED_UNQUOTED = re.compile(r"^[a-zA-Z0-9_-]+$")
105 106
106 107
107 class APGateway: 108 class APGateway:
109 IMPORT_NAME = IMPORT_NAME
108 110
109 def __init__(self, host): 111 def __init__(self, host):
110 self.host = host 112 self.host = host
111 self.initialised = False 113 self.initialised = False
112 self.client = None 114 self.client = None
115 self._p = host.plugins["XEP-0060"]
116 self._a = host.plugins["XEP-0084"]
117 self._e = host.plugins["XEP-0106"]
113 self._m = host.plugins["XEP-0277"] 118 self._m = host.plugins["XEP-0277"]
114 self._p = host.plugins["XEP-0060"] 119 self._v = host.plugins["XEP-0292"]
115 self._e = host.plugins["XEP-0106"]
116 self._r = host.plugins["XEP-0424"] 120 self._r = host.plugins["XEP-0424"]
117 self._pps = host.plugins["XEP-0465"] 121 self._pps = host.plugins["XEP-0465"]
118 self._c = host.plugins["PUBSUB_CACHE"] 122 self._c = host.plugins["PUBSUB_CACHE"]
123 self._t = host.plugins["TEXT_SYNTAXES"]
124 self._i = host.plugins["IDENTITY"]
119 self._p.addManagedNode( 125 self._p.addManagedNode(
120 "", items_cb=self._itemsReceived 126 "", items_cb=self._itemsReceived
121 ) 127 )
122 self._t = host.plugins["TEXT_SYNTAXES"]
123 self.pubsub_service = APPubsubService(self) 128 self.pubsub_service = APPubsubService(self)
124 host.trigger.add("messageReceived", self._messageReceivedTrigger, priority=-1000) 129 host.trigger.add("messageReceived", self._messageReceivedTrigger, priority=-1000)
125 host.trigger.add("XEP-0424_retractReceived", self._onMessageRetract) 130 host.trigger.add("XEP-0424_retractReceived", self._onMessageRetract)
126 131
127 host.bridge.addMethod( 132 host.bridge.addMethod(
228 reactor.listenSSL(self.http_port, self.server, context_factory) 233 reactor.listenSSL(self.http_port, self.server, context_factory)
229 234
230 async def profileConnecting(self, client): 235 async def profileConnecting(self, client):
231 self.client = client 236 self.client = client
232 client.sendHistory = True 237 client.sendHistory = True
238 client._ap_storage = persistent.LazyPersistentBinaryDict(
239 IMPORT_NAME,
240 client.profile
241 )
233 await self.init(client) 242 await self.init(client)
234 243
235 async def _itemsReceived( 244 async def _itemsReceived(
236 self, 245 self,
237 client: SatXMPPEntity, 246 client: SatXMPPEntity,