diff libervia/web/pages/_browser/invitation.py @ 1531:d7c78722e4f8

browser (cache): make `fill_identities` async + use `json` module: - `json` module has been greatly improved in Brython, the former workaround is not needed anymore. - `fill_identities` is now async so an async method can wait for it to complete
author Goffi <goffi@goffi.org>
date Thu, 22 Jun 2023 16:35:34 +0200
parents eb00d593801d
children 7228fc3c4744
line wrap: on
line diff
--- a/libervia/web/pages/_browser/invitation.py	Thu Jun 08 23:32:47 2023 +0200
+++ b/libervia/web/pages/_browser/invitation.py	Thu Jun 22 16:35:34 2023 +0200
@@ -1,9 +1,9 @@
-from browser import document, window, timer
 from bridge import Bridge
+from browser import document, timer, window
+from cache import cache
+import dialog
+import javascript
 from template import Template
-import dialog
-from cache import cache
-import javascript
 
 bridge = Bridge()
 # we use JS RegExp because Python's re is really long to import in Brython
@@ -26,7 +26,7 @@
         self._active_new_item = None
         self._idx = 0
 
-    def attach(self, affiliations=None):
+    async def attach(self, affiliations=None):
         if affiliations is None:
             affiliations = {}
         self.affiliations = affiliations
@@ -37,7 +37,9 @@
             close_elt.bind("click", self.on_manager_close)
         self.side_panel.bind("click", lambda evt: evt.stopPropagation())
 
-        cache.fill_identities(affiliations.keys(), callback=self._set_affiliations)
+        await cache.fill_identities(affiliations.keys())
+        for entity_jid, affiliation in self.affiliations.items():
+            self.set_affiliation(entity_jid, affiliation)
 
         contact_elt = self.manager_panel_elt.select_one('input[name="contact"]')
         contact_elt.bind("input", self.on_contact_input)
@@ -46,10 +48,6 @@
         contact_elt.bind("blur", self.on_contact_blur)
         document['invite_email'].bind('click', self.on_invite_email_click)
 
-    def _set_affiliations(self):
-        for entity_jid, affiliation in self.affiliations.items():
-            self.set_affiliation(entity_jid, affiliation)
-
     def open(self):
         """Re-attach and show a closed panel"""
         self._body_ori_style = document.body.style.height, document.body.style.overflow