Mercurial > libervia-web
annotate libervia/web/pages/_browser/jid_search.py @ 1566:e65d2ef1ded4
browser (calls/webrtc): send ICE candidates when received:
- ICE candidates gathering is not waited for anymore
- if session is not ready, candidates are buffered and replayed when suitable
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 21 Aug 2023 15:36:09 +0200 |
parents | 5c4703870088 |
children | 02432346e9b2 |
rev | line source |
---|---|
1548
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
1 import json |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
2 from urllib.parse import quote, urljoin |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
3 |
1546
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 from bridge import AsyncBridge as Bridge |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 from browser import aio, console as log, window |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 from cache import cache |
1548
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
7 from template import Template |
1546
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 log.warning = log.warn |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 profile = window.profile or "" |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 bridge = Bridge() |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 class JidSearch: |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 |
1548
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
15 def __init__( |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
16 self, |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
17 search_elt, |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
18 container_elt=None, |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
19 filter_cb=None, |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
20 empty_cb=None, |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
21 get_url=None, |
1556
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
22 click_cb=None, |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
23 options: dict|None = None, |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
24 template: str = "components/search_item.html" |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
25 ) -> None: |
1548
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
26 """Initialize the JidSearch instance |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
27 |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
28 @param search_elt: The HTML <input> element for search |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
29 @param container_elt: The HTML container to display the search results |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
30 @param filter_cb: The callback to filter the search results |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
31 @param empty_cb: The callback when the search box is empty |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
32 @param get_url: The function to get URL for each entity in the search result |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
33 @param click_cb: The function to handle the click event on each entity in the |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
34 search result |
1556
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
35 @param options: extra options. Key can be: |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
36 no_group(bool) |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
37 True if groups should not be visible |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
38 extra_cb(dict) |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
39 a map from CSS selector to callback, the callback will be binded to the |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
40 "click" event, and will be called with the ``item`` as argument |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
41 @param template: template to use |
1548
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
42 """ |
1556
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
43 self.search_item_tpl = Template(template) |
1546
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 self.search_elt = search_elt |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 self.search_elt.bind("input", self.on_search_input) |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 self.last_query = None |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 self.current_query = None |
1548
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
48 self.container_elt = container_elt |
1556
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
49 if options is None: |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
50 options = {} |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
51 self.options = options |
1548
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
52 |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
53 if click_cb is not None and get_url is None: |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
54 self.get_url = lambda _: "#" |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
55 else: |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
56 self.get_url = get_url if get_url is not None else self.default_get_url |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
57 self.click_cb = click_cb |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
58 |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
59 if filter_cb is None: |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
60 if container_elt is None: |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
61 raise ValueError("container_elt must be set if filter_cb is not set") |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
62 filter_cb = self.show_items |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
63 self.filter_cb = filter_cb |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
64 |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
65 self.empty_cb = empty_cb or self.on_empty_search |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
66 |
1546
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 current_search = search_elt.value.strip() or None |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1548
diff
changeset
|
68 if not current_search: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1548
diff
changeset
|
69 self.empty_cb() |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1548
diff
changeset
|
70 else: |
1546
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 aio.run(self.perform_search(current_search)) |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 |
1548
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
73 def default_get_url(self, item): |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
74 """Default method to get the URL for a given entity |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
75 |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
76 @param item: The item (entity) for which the URL is required |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
77 """ |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
78 return urljoin(f"{window.location.href}/", quote(item["entity"])) |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
79 |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
80 def show_items(self, items): |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
81 """Display the search items in the specified container |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
82 |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
83 @param items: The list of search items to be displayed |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
84 """ |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
85 assert self.container_elt is not None |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
86 self.container_elt.clear() |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
87 for item in items: |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
88 search_item_elt = self.search_item_tpl.get_elt({ |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
89 "url": self.get_url(item), |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
90 "item": item, |
1556
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
91 "identities": cache.identities, |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
92 "options": self.options, |
1548
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
93 }) |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
94 if self.click_cb is not None: |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
95 search_item_elt.bind('click', lambda evt, item=item: self.click_cb(item)) |
1556
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
96 extra_cb = self.options.get("extra_cb") |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
97 if extra_cb: |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
98 for selector, cb in extra_cb.items(): |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
99 for elt in search_item_elt.select(selector): |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
100 log.debug(f"binding {selector=} {elt=} {cb=} {id(cb)=}") |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
101 elt.bind( |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
102 "click", |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
103 lambda evt, item=item, cb=cb: cb(evt, item) |
5c4703870088
browser (jid_search): search items can now be customised:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
104 ) |
1548
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
105 self.container_elt <= search_item_elt |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
106 |
1546
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 def on_search_input(self, evt): |
1548
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
108 """Handle the 'input' event for the search element |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
109 |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
110 @param evt: The event object |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
111 """ |
1546
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 search_text = evt.target.value.strip() |
1548
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
113 if not search_text: |
1546
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 self.empty_cb() |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 elif len(search_text) > 2: |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 aio.run(self.perform_search(search_text)) |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 async def perform_search(self, query): |
1548
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
119 """Perform the search operation for a given query |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
120 |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
121 @param query: The search query |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
122 """ |
1546
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 if self.current_query is None: |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 log.debug(f"performing search: {query=}") |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 self.current_query = query |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 jid_items = json.loads(await bridge.jid_search(query, "")) |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 await cache.fill_identities(i["entity"] for i in jid_items) |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 self.last_query = query |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 self.current_query = None |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 current_query = self.search_elt.value.strip() |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 if current_query != query: |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 await self.perform_search(current_query) |
7f3f5ae7d65a
browser (jid_search): implement a mechanism to get JIDs from search terms
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 return |
1548
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
135 self.filter_cb(jid_items) |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
136 |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
137 def on_empty_search(self): |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
138 """Handle the situation when the search box is empty""" |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
139 assert self.container_elt is not None |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
140 items = [ |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
141 { |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
142 "entity": jid_, |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
143 "groups": data["groups"] |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
144 } |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
145 for jid_, data in cache.roster.items() |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
146 ] |
66aa6e140ebb
browser: make `jid_search` more generic:
Goffi <goffi@goffi.org>
parents:
1546
diff
changeset
|
147 self.show_items(items) |