Mercurial > libervia-backend
comparison sat/core/sat_main.py @ 3541:888109774673
core: various changes and fixes to work with new storage and D-Bus bridge:
- fixes coroutines handling in various places
- fixes types which are not serialised by Tx DBus
- XEP-0384: call storage methods in main thread in XEP: Python OMEMO's Promise use thread
which prevent the use of AsyncIO loop. To work around that, callLater is used to launch
storage method in main thread. This is a temporary workaround, as Python OMEMO should
get rid of Promise implementation and threads soon.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 03 Jun 2021 15:21:43 +0200 |
parents | 60d3861e5996 |
children | 7bc443253b7c |
comparison
equal
deleted
inserted
replaced
3540:aa58451b77ba | 3541:888109774673 |
---|---|
454 try: | 454 try: |
455 unload = plugin.unload | 455 unload = plugin.unload |
456 except AttributeError: | 456 except AttributeError: |
457 continue | 457 continue |
458 else: | 458 else: |
459 defers_list.append(defer.maybeDeferred(unload)) | 459 defers_list.append(utils.asDeferred(unload)) |
460 return defers_list | 460 return defers_list |
461 | 461 |
462 def _connect(self, profile_key, password="", options=None): | 462 def _connect(self, profile_key, password="", options=None): |
463 profile = self.memory.getProfileName(profile_key) | 463 profile = self.memory.getProfileName(profile_key) |
464 return defer.ensureDeferred(self.connect(profile, password, options)) | 464 return defer.ensureDeferred(self.connect(profile, password, options)) |
468 """Connect a profile (i.e. connect client.component to XMPP server) | 468 """Connect a profile (i.e. connect client.component to XMPP server) |
469 | 469 |
470 Retrieve the individual parameters, authenticate the profile | 470 Retrieve the individual parameters, authenticate the profile |
471 and initiate the connection to the associated XMPP server. | 471 and initiate the connection to the associated XMPP server. |
472 @param profile: %(doc_profile)s | 472 @param profile: %(doc_profile)s |
473 @param password (string): the SàT profile password | 473 @param password (string): the Libervia profile password |
474 @param options (dict): connection options. Key can be: | 474 @param options (dict): connection options. Key can be: |
475 - | 475 - |
476 @param max_retries (int): max number of connection retries | 476 @param max_retries (int): max number of connection retries |
477 @return (D(bool)): | 477 @return (D(bool)): |
478 - True if the XMPP connection was already established | 478 - True if the XMPP connection was already established |
531 pass | 531 pass |
532 | 532 |
533 features = [] | 533 features = [] |
534 for import_name, plugin in self.plugins.items(): | 534 for import_name, plugin in self.plugins.items(): |
535 try: | 535 try: |
536 features_d = defer.maybeDeferred(plugin.getFeatures, profile_key) | 536 features_d = utils.asDeferred(plugin.getFeatures, profile_key) |
537 except AttributeError: | 537 except AttributeError: |
538 features_d = defer.succeed({}) | 538 features_d = defer.succeed({}) |
539 features.append(features_d) | 539 features.append(features_d) |
540 | 540 |
541 d_list = defer.DeferredList(features) | 541 d_list = defer.DeferredList(features) |
579 for item in client.roster.getItems(): # we get all items for client's roster | 579 for item in client.roster.getItems(): # we get all items for client's roster |
580 # and convert them to expected format | 580 # and convert them to expected format |
581 attr = client.roster.getAttributes(item) | 581 attr = client.roster.getAttributes(item) |
582 # we use full() and not userhost() because jid with resources are allowed | 582 # we use full() and not userhost() because jid with resources are allowed |
583 # in roster, even if it's not common. | 583 # in roster, even if it's not common. |
584 ret.append([item.entity.full(), attr, item.groups]) | 584 ret.append([item.entity.full(), attr, list(item.groups)]) |
585 return ret | 585 return ret |
586 | 586 |
587 return client.roster.got_roster.addCallback(got_roster) | 587 return client.roster.got_roster.addCallback(got_roster) |
588 | 588 |
589 def getContactsFromGroup(self, group, profile_key): | 589 def getContactsFromGroup(self, group, profile_key): |
1106 return self.memory.disco.findFeaturesSet(*args, **kwargs) | 1106 return self.memory.disco.findFeaturesSet(*args, **kwargs) |
1107 | 1107 |
1108 def _findByFeatures(self, namespaces, identities, bare_jids, service, roster, own_jid, | 1108 def _findByFeatures(self, namespaces, identities, bare_jids, service, roster, own_jid, |
1109 local_device, profile_key): | 1109 local_device, profile_key): |
1110 client = self.getClient(profile_key) | 1110 client = self.getClient(profile_key) |
1111 identities = [tuple(i) for i in identities] if identities else None | |
1111 return defer.ensureDeferred(self.findByFeatures( | 1112 return defer.ensureDeferred(self.findByFeatures( |
1112 client, namespaces, identities, bare_jids, service, roster, own_jid, | 1113 client, namespaces, identities, bare_jids, service, roster, own_jid, |
1113 local_device)) | 1114 local_device)) |
1114 | 1115 |
1115 async def findByFeatures( | 1116 async def findByFeatures( |