annotate libervia/web/pages/_browser/cache.py @ 1619:a2cd4222c702

browser: Updates for new design: This patch add code to handle the new design for chat. New bridge method are used to invite users to MUC or get list of occupants. A new modules is used for components, with a first one for collapsible cards. rel 457
author Goffi <goffi@goffi.org>
date Sat, 12 Apr 2025 00:21:45 +0200
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
1619
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1544
diff changeset
5 import javascript
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
6 import json
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
7
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
8 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
9 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
10 bridge = Bridge()
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
11 async_bridge = AsyncBridge()
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
12
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # 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
14 # 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
15 # 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
16 # other)
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
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 class Cache:
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
20
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 def __init__(self):
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 try:
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 cache = storage['libervia_cache']
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 except KeyError:
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 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
26 else:
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
27 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
28 if cache['metadata']['session_uuid'] != session_uuid:
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
29 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
30 del storage['libervia_cache']
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 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
32 else:
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 self._cache = cache
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
34 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
35
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 @property
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 def roster(self):
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 return self._cache['roster']
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
39
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 @property
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 def identities(self):
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 return self._cache['identities']
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
43
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 def update(self):
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
45 log.debug(f"updating: {self._cache}")
1619
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1544
diff changeset
46 # FIXME: workaround in Brython 3.13.0
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1544
diff changeset
47 # storage['libervia_cache'] = json.dumps(self._cache)
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1544
diff changeset
48 storage['libervia_cache'] = javascript.JSON.stringify(self._cache)
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
49 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
50
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 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
52 self._completed_count -= 1
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 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
54 del self._completed_count
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self.update()
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
56
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1431
diff changeset
57 def get_contacts_cb(self, contacts):
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
58 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
59 roster = self._cache['roster']
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 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
61 roster[contact_jid] = {
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 'attributes': attributes,
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 'groups': groups,
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 }
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 self._store_if_complete()
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
66
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1431
diff changeset
67 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
68 log.debug("base identities received")
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
69 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
70 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
71 self._store_if_complete()
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
72
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 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
74 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
75 self._store_if_complete()
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
76
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 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
78 self._cache = {
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 'metadata': {
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 "session_uuid": session_uuid,
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 'roster': {},
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 'identities': {},
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 }
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 self._completed_count = 2
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
86 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
87 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
88 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
89 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
90 )
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
91 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
92 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
93 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
94 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
95 )
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
96
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
97 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
98 """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
99 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
100 if to_get:
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
101 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
102 try:
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
103 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
104 list(to_get),
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
105 ['avatar', 'nicknames'],
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
106 )
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
107 except Exception as e:
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
108 notification.show(
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
109 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
110 "error"
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 )
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
112 else:
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
113 new_identities = json.loads(new_identities_raw)
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
114 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
115 self._cache['identities'].update(new_identities)
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
116 self.update()
1329
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 else:
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 # we already have all identities
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
119 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
120
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 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
122 """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
123
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 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
125 @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
126 @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
127 @param identity: identity data
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 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
129 @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
130 """
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 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
132 return True
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 if identity is None:
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 try:
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 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
136 except KeyError:
1544
9b451115e726 browser (cache): replace `print` by `log` calls
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
137 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
138 return False
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 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
140
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 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
142 """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
143
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 """
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 text = text.lower().strip()
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 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
147 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
148 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
149 )):
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 yield entity_jid
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
151
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
152
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 cache = Cache()
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 roster = cache.roster
ed28ad7d484c browser (cache): new `cache` module to handle cache of roster and identities:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 identities = cache.identities