Mercurial > libervia-web
diff libervia/web/pages/_browser/jid_search.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 | 4a9679369856 |
children |
line wrap: on
line diff
--- a/libervia/web/pages/_browser/jid_search.py Sat Oct 26 23:07:01 2024 +0200 +++ b/libervia/web/pages/_browser/jid_search.py Sat Apr 12 00:21:45 2025 +0200 @@ -1,9 +1,11 @@ import json +from typing import Callable from urllib.parse import quote, urljoin from bridge import AsyncBridge as Bridge from browser import aio, console as log, window from cache import cache +import errors from template import Template import jid @@ -17,7 +19,7 @@ self, search_elt, container_elt=None, - filter_cb=None, + filter_cb: Callable[[list[str]], None]|None = None, empty_cb=None, get_url=None, click_cb=None, @@ -39,7 +41,9 @@ search result @param options: extra options. Key can be: no_group(bool) - True if groups should not be visible + True if entity groups should not be visible + type (str) + Can be "group" or "one2one". Default to one2one. extra_cb(dict) a map from CSS selector to callback, the callback will be binded to the "click" event, and will be called with the ``item`` as argument @@ -52,6 +56,8 @@ @param selection_state_callback: A callback function to execute when selection state changes. Takes one boolean parameter indicating if items are selected. """ + self.selected = set() + self.current_items = set() self.search_item_tpl = Template(template) self.search_elt = search_elt self.search_elt.bind("input", self.on_search_input) @@ -68,6 +74,13 @@ if options is None: options = {} self.options = options + match options.get("type"): + case None | "one2one": + self.group = False + case "group": + self.group = True + case _: + raise errors.InternalError(f"Invalid type: {options.get('type')!r}.") if click_cb is not None and get_url is None: self.get_url = lambda _: "#" @@ -194,7 +207,11 @@ if self.current_query is None: log.debug(f"performing search: {query=}") self.current_query = query - jid_items = json.loads(await bridge.jid_search(query, "")) + if self.group: + options = {"entities": False, "groupchat": True} + else: + options = {"entities": True, "groupchat": False} + jid_items = json.loads(await bridge.jid_search(query, json.dumps(options))) await cache.fill_identities(i["entity"] for i in jid_items) self.last_query = query @@ -221,13 +238,16 @@ async def on_empty_search(self, jid_search): """Handle the situation when the search box is empty""" assert self.container_elt is not None - items = [ - { - "entity": jid_, - "groups": data["groups"] - } - for jid_, data in cache.roster.items() - ] + if self.group: + items = [] + else: + items = [ + { + "entity": jid_, + "groups": data["groups"] + } + for jid_, data in cache.roster.items() + ] self.show_items(items) def on_checkbox_change(self, evt, item):