Mercurial > libervia-web
comparison libervia/pages/_browser/cache.py @ 1509:106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:44:11 +0200 |
parents | 7472d5a88006 |
children | 5ea06e8b06ed |
comparison
equal
deleted
inserted
replaced
1508:ec3ad9abf9f9 | 1509:106bae41f5c8 |
---|---|
1 from browser import window | 1 from browser import window |
2 from browser.local_storage import storage | 2 from browser.local_storage import storage |
3 from javascript import JSON | 3 from javascript import JSON |
4 from dialog import notification | 4 from dialog import notification |
5 from bridge import Bridge | 5 from bridge import bridge |
6 | 6 |
7 session_uuid = window.session_uuid | 7 session_uuid = window.session_uuid |
8 bridge = Bridge() | 8 bridge = bridge() |
9 | 9 |
10 # XXX: we don't use browser.object_storage because it is affected by | 10 # XXX: we don't use browser.object_storage because it is affected by |
11 # https://github.com/brython-dev/brython/issues/1467 and mixing local_storage.storage | 11 # https://github.com/brython-dev/brython/issues/1467 and mixing local_storage.storage |
12 # and object_storage was resulting in weird behaviour (keys found in one not in the | 12 # and object_storage was resulting in weird behaviour (keys found in one not in the |
13 # other) | 13 # other) |
49 self._completed_count -= 1 | 49 self._completed_count -= 1 |
50 if self._completed_count == 0: | 50 if self._completed_count == 0: |
51 del self._completed_count | 51 del self._completed_count |
52 self.update() | 52 self.update() |
53 | 53 |
54 def getContactsCb(self, contacts): | 54 def get_contacts_cb(self, contacts): |
55 print("roster received") | 55 print("roster received") |
56 roster = self._cache['roster'] | 56 roster = self._cache['roster'] |
57 for contact_jid, attributes, groups in contacts: | 57 for contact_jid, attributes, groups in contacts: |
58 roster[contact_jid] = { | 58 roster[contact_jid] = { |
59 'attributes': attributes, | 59 'attributes': attributes, |
60 'groups': groups, | 60 'groups': groups, |
61 } | 61 } |
62 self._store_if_complete() | 62 self._store_if_complete() |
63 | 63 |
64 def identitiesBaseGetCb(self, identities_raw): | 64 def identities_base_get_cb(self, identities_raw): |
65 print("base identities received") | 65 print("base identities received") |
66 identities = JSON.parse(identities_raw) | 66 identities = JSON.parse(identities_raw) |
67 self._cache['identities'].update(identities) | 67 self._cache['identities'].update(identities) |
68 self._store_if_complete() | 68 self._store_if_complete() |
69 | 69 |
79 'roster': {}, | 79 'roster': {}, |
80 'identities': {}, | 80 'identities': {}, |
81 } | 81 } |
82 self._completed_count = 2 | 82 self._completed_count = 2 |
83 print("requesting roster to backend") | 83 print("requesting roster to backend") |
84 bridge.getContacts( | 84 bridge.contacts_get( |
85 callback=self.getContactsCb, | 85 callback=self.get_contacts_cb, |
86 errback=lambda e: self.request_failed(e, "Can't get contacts: {exc}") | 86 errback=lambda e: self.request_failed(e, "Can't get contacts: {exc}") |
87 ) | 87 ) |
88 print("requesting base identities to backend") | 88 print("requesting base identities to backend") |
89 bridge.identitiesBaseGet( | 89 bridge.identities_base_get( |
90 callback=self.identitiesBaseGetCb, | 90 callback=self.identities_base_get_cb, |
91 errback=lambda e: self.request_failed(e, "Can't get base identities: {exc}") | 91 errback=lambda e: self.request_failed(e, "Can't get base identities: {exc}") |
92 ) | 92 ) |
93 | 93 |
94 def _fill_identities_cb(self, new_identities_raw, callback): | 94 def _fill_identities_cb(self, new_identities_raw, callback): |
95 new_identities = JSON.parse(new_identities_raw) | 95 new_identities = JSON.parse(new_identities_raw) |
101 | 101 |
102 def fill_identities(self, entities, callback=None): | 102 def fill_identities(self, entities, callback=None): |
103 """Check that identities for entities exist, request them otherwise""" | 103 """Check that identities for entities exist, request them otherwise""" |
104 to_get = {e for e in entities if e not in self._cache['identities']} | 104 to_get = {e for e in entities if e not in self._cache['identities']} |
105 if to_get: | 105 if to_get: |
106 bridge.identitiesGet( | 106 bridge.identities_get( |
107 list(to_get), | 107 list(to_get), |
108 ['avatar', 'nicknames'], | 108 ['avatar', 'nicknames'], |
109 callback=lambda identities: self._fill_identities_cb( | 109 callback=lambda identities: self._fill_identities_cb( |
110 identities, callback), | 110 identities, callback), |
111 errback=lambda failure_: notification.show( | 111 errback=lambda failure_: notification.show( |