Mercurial > libervia-backend
diff sat/core/sat_main.py @ 4041:2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 15 May 2023 16:20:45 +0200 |
parents | 524856bd7b19 |
children | 9641ce286e07 |
line wrap: on
line diff
--- a/sat/core/sat_main.py Mon May 15 16:20:38 2023 +0200 +++ b/sat/core/sat_main.py Mon May 15 16:20:45 2023 +0200 @@ -36,6 +36,7 @@ from wokkel.xmppim import RosterItem from sat.core import xmpp from sat.core import exceptions +from sat.core.core_types import SatXMPPEntity from sat.core.log import getLogger from sat.core.constants import Const as C @@ -201,7 +202,7 @@ self.bridge.register_method("contact_del", self._del_contact) self.bridge.register_method("roster_resync", self._roster_resync) self.bridge.register_method("is_connected", self.is_connected) - self.bridge.register_method("action_launch", self.launch_callback) + self.bridge.register_method("action_launch", self._action_launch) self.bridge.register_method("actions_get", self.actions_get) self.bridge.register_method("progress_get", self._progress_get) self.bridge.register_method("progress_get_all", self._progress_get_all) @@ -885,7 +886,7 @@ def get_local_path( self, - client: Optional[xmpp.SatXMPPEntity], + client: Optional[SatXMPPEntity], dir_name: str, *extra_path: str, component: bool = False, @@ -1119,7 +1120,7 @@ async def find_by_features( self, - client: xmpp.SatXMPPEntity, + client: SatXMPPEntity, namespaces: List[str], identities: Optional[List[Tuple[str, str]]]=None, bare_jids: bool=False, @@ -1277,7 +1278,9 @@ action_timer = reactor.callLater(60 * 30, self._kill_action, keep_id, client) client.actions[keep_id] = (action_data, id_, security_limit, action_timer) - self.bridge.action_new(action_data, id_, security_limit, profile) + self.bridge.action_new( + data_format.serialise(action_data), id_, security_limit, profile + ) def actions_get(self, profile): """Return current non answered actions @@ -1285,7 +1288,10 @@ @param profile: %(doc_profile)s """ client = self.get_client(profile) - return [action_tuple[:-1] for action_tuple in client.actions.values()] + return [ + (data_format.serialise(action_tuple[0]), *action_tuple[1:-1]) + for action_tuple in client.actions.values() + ] def register_progress_cb( self, progress_id, callback, metadata=None, profile=C.PROF_KEY_NONE @@ -1401,7 +1407,7 @@ def purge_callback(): try: - self.removeCallback(callback_id) + self.remove_callback(callback_id) except KeyError: pass @@ -1409,13 +1415,32 @@ return callback_id - def removeCallback(self, callback_id): + def remove_callback(self, callback_id): """ Remove a previously registered callback @param callback_id: id returned by [register_callback] """ log.debug("Removing callback [%s]" % callback_id) del self._cb_map[callback_id] - def launch_callback(self, callback_id, data=None, profile_key=C.PROF_KEY_NONE): + def _action_launch( + self, + callback_id: str, + data_s: str, + profile_key: str + ) -> defer.Deferred: + d = self.launch_callback( + callback_id, + data_format.deserialise(data_s), + profile_key + ) + d.addCallback(data_format.serialise) + return d + + def launch_callback( + self, + callback_id: str, + data: Optional[dict] = None, + profile_key: str = C.PROF_KEY_NONE + ) -> defer.Deferred: """Launch a specific callback @param callback_id: id of the action (callback) to launch @@ -1428,7 +1453,9 @@ - C.BOOL_TRUE - C.BOOL_FALSE """ - # Â FIXME: security limit need to be checked here + # FIXME: is it possible to use this method without profile connected? If not, + # client must be used instead of profile_key + # FIXME: security limit need to be checked here try: client = self.get_client(profile_key) except exceptions.NotFound: @@ -1466,7 +1493,7 @@ del kwargs["with_data"] if kwargs.pop("one_shot", False): - self.removeCallback(callback_id) + self.remove_callback(callback_id) return utils.as_deferred(callback, *args, **kwargs)