annotate libervia/web/pages/_browser/cache.py @ 1587:860e33127245

browser (slideshow): fix use of `current_slide` when there is no slide.
author Goffi <goffi@goffi.org>
date Sun, 10 Dec 2023 10:57:48 +0100
parents 9b451115e726
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
1 from browser import window, console as log
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 from browser.local_storage import storage
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 from dialog import notification
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
4 from bridge import Bridge, AsyncBridge
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
5 import json
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
7 log.warning = log.warn
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 session_uuid = window.session_uuid
1510
5ea06e8b06ed browser: make bridge API closer to the one use with other frontends:
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
9 bridge = Bridge()
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
10 async_bridge = AsyncBridge()
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # XXX: we don't use browser.object_storage because it is affected by
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # https://github.com/brython-dev/brython/issues/1467 and mixing local_storage.storage
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # and object_storage was resulting in weird behaviour (keys found in one not in the
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # other)
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
17
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 class Cache:
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 def __init__(self):
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 try:
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 cache = storage['libervia_cache']
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 except KeyError:
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 self.request_data_from_backend()
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 else:
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
26 cache = json.loads(cache)
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 if cache['metadata']['session_uuid'] != session_uuid:
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
28 log.debug("data in cache are not valid for this session, resetting")
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 del storage['libervia_cache']
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 self.request_data_from_backend()
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 else:
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 self._cache = cache
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
33 log.debug("storage cache is used")
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
34
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 @property
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 def roster(self):
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 return self._cache['roster']
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
38
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 @property
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 def identities(self):
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 return self._cache['identities']
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
42
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 def update(self):
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
44 log.debug(f"updating: {self._cache}")
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
45 storage['libervia_cache'] = json.dumps(self._cache)
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
46 log.debug("cache stored")
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
47
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 def _store_if_complete(self):
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 self._completed_count -= 1
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 if self._completed_count == 0:
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 del self._completed_count
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self.update()
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
53
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1431
diff changeset
54 def get_contacts_cb(self, contacts):
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
55 log.debug("roster received")
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 roster = self._cache['roster']
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 for contact_jid, attributes, groups in contacts:
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 roster[contact_jid] = {
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 'attributes': attributes,
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 'groups': groups,
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 }
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 self._store_if_complete()
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
63
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1431
diff changeset
64 def identities_base_get_cb(self, identities_raw):
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
65 log.debug("base identities received")
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
66 identities = json.loads(identities_raw)
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 self._cache['identities'].update(identities)
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 self._store_if_complete()
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
69
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 def request_failed(self, exc, message):
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 notification.show(message.format(exc=exc), "error")
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 self._store_if_complete()
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
73
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 def request_data_from_backend(self):
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 self._cache = {
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 'metadata': {
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 "session_uuid": session_uuid,
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 },
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 'roster': {},
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 'identities': {},
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 }
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 self._completed_count = 2
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
83 log.debug("requesting roster to backend")
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1431
diff changeset
84 bridge.contacts_get(
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1431
diff changeset
85 callback=self.get_contacts_cb,
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 errback=lambda e: self.request_failed(e, "Can't get contacts: {exc}")
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 )
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
88 log.debug("requesting base identities to backend")
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1431
diff changeset
89 bridge.identities_base_get(
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1431
diff changeset
90 callback=self.identities_base_get_cb,
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 errback=lambda e: self.request_failed(e, "Can't get base identities: {exc}")
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 )
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
93
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
94 async def fill_identities(self, entities) -> None:
1431
7472d5a88006 browser(bridge): allow some bridge methods for session profile:
Goffi <goffi@goffi.org>
parents: 1329
diff changeset
95 """Check that identities for entities exist, request them otherwise"""
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 to_get = {e for e in entities if e not in self._cache['identities']}
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 if to_get:
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
98 log.debug(f"we don't have all identities in cache, getting {to_get}")
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
99 try:
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
100 new_identities_raw = await async_bridge.identities_get(
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
101 list(to_get),
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
102 ['avatar', 'nicknames'],
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
103 )
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
104 except Exception as e:
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
105 notification.show(
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
106 f"Can't get identities: {e}",
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 "error"
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 )
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
109 else:
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
110 new_identities = json.loads(new_identities_raw)
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
111 log.debug(f"new identities: {new_identities.keys()}")
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
112 self._cache['identities'].update(new_identities)
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
113 self.update()
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 else:
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 # we already have all identities
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
116 log.debug("no missing identity")
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
117
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 def match_identity(self, entity_jid, text, identity=None):
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 """Returns True if a text match an entity identity
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
120
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 identity will be matching if its jid or any of its name contain text
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 @param entity_jid: jid of the entity to check
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 @param text: text to use for filtering. Must be in lowercase and stripped
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 @param identity: identity data
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 if None, it will be retrieved if jid is not matching
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 @return: True if entity is matching
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 """
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 if text in entity_jid:
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 return True
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 if identity is None:
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 try:
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 identity = self.identities[entity_jid]
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 except KeyError:
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
134 log.debug(f"missing identity: {entity_jid}")
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 return False
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 return any(text in n.lower() for n in identity['nicknames'])
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
137
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 def matching_identities(self, text):
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 """Return identities corresponding to a text
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
140
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 """
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 text = text.lower().strip()
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 for entity_jid, identity in self._cache['identities'].items():
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 if ((text in entity_jid
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 or any(text in n.lower() for n in identity['nicknames'])
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 )):
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 yield entity_jid
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
148
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
149
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 cache = Cache()
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 roster = cache.roster
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 identities = cache.identities