changeset 1593:c6976c5b85a1

browser (chat/select): add bookmarked entities on empty search
author Goffi <goffi@goffi.org>
date Mon, 11 Dec 2023 00:43:06 +0100
parents 291a7026cb2b
children 93abef9a3548
files libervia/web/pages/_browser/jid_search.py libervia/web/pages/chat/select/_browser/__init__.py libervia/web/pages/chat/select/page_meta.py libervia/web/server/restricted_bridge.py
diffstat 4 files changed, 38 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/web/pages/_browser/jid_search.py	Sun Dec 10 18:33:00 2023 +0100
+++ b/libervia/web/pages/_browser/jid_search.py	Mon Dec 11 00:43:06 2023 +0100
@@ -76,7 +76,7 @@
 
         current_search = search_elt.value.strip() or None
         if not current_search:
-            self.empty_cb()
+            aio.run(self.empty_cb(self))
         else:
             aio.run(self.perform_search(current_search))
 
@@ -123,7 +123,7 @@
         evt.preventDefault()
         search_text = evt.target.value.strip()
         if not search_text:
-            self.empty_cb()
+            aio.run(self.empty_cb(self))
         elif len(search_text) > 2:
             aio.run(self.perform_search(search_text))
 
@@ -153,7 +153,7 @@
                 return
             self.filter_cb(jid_items)
 
-    def on_empty_search(self):
+    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 = [
--- a/libervia/web/pages/chat/select/_browser/__init__.py	Sun Dec 10 18:33:00 2023 +0100
+++ b/libervia/web/pages/chat/select/_browser/__init__.py	Mon Dec 11 00:43:06 2023 +0100
@@ -1,13 +1,31 @@
 
 from bridge import AsyncBridge as Bridge
-from browser import console as log, document, window
+from browser import console as log, document
 from cache import cache
 from jid_search import JidSearch
 
+bridge = Bridge()
 log.warning = log.warn
 
 
+async def empty_search(jid_search):
+    # FIXME: this is Q&D way to add bookmarks, a proper handling of joined room must be
+    #   done
+    items = [
+        {
+            "entity": jid_,
+            "groups": data["groups"]
+        }
+        for jid_, data in cache.roster.items()
+    ]
+    bookmarks = await bridge.bookmarks_list("muc", "all")
+    for bm_values in list(bookmarks.values()):
+        for room_jid, room_data in bm_values.items():
+            items.append({"entity": room_jid})
+    jid_search.show_items(items)
+
 jid_search = JidSearch(
     document["search"],
     document["chat_items"],
+    empty_cb = empty_search
 )
--- a/libervia/web/pages/chat/select/page_meta.py	Sun Dec 10 18:33:00 2023 +0100
+++ b/libervia/web/pages/chat/select/page_meta.py	Mon Dec 11 00:43:06 2023 +0100
@@ -15,12 +15,11 @@
 template = "chat/select.html"
 
 
-@defer.inlineCallbacks
-def prepare_render(self, request):
+async def prepare_render(self, request):
     profile = self.get_profile(request)
     template_data = request.template_data
     rooms = template_data["rooms"] = []
-    bookmarks = yield self.host.bridge_call("bookmarks_list", "muc", "all", profile)
+    bookmarks = await self.host.bridge_call("bookmarks_list", "muc", "all", profile)
     for bm_values in list(bookmarks.values()):
         for room_jid, room_data in bm_values.items():
             url = self.get_page_by_name("chat").get_url(room_jid)
@@ -28,18 +27,17 @@
     rooms.sort(key=lambda r: r.name)
 
 
-@defer.inlineCallbacks
-def on_data_post(self, request):
+async def on_data_post(self, request):
     jid_ = self.get_posted_data(request, "search")
     if "@" not in jid_:
         profile = self.get_profile(request)
-        service = yield self.host.bridge_call("muc_get_service", "", profile)
+        service = await self.host.bridge_call("muc_get_service", "", profile)
         if service:
             muc_jid = jid.JID(service)
             muc_jid.user = jid_
             jid_ = muc_jid.full()
         else:
             log.warning(_("Invalid jid received: {jid}".format(jid=jid_)))
-            defer.returnValue(C.POST_NO_CONFIRM)
+            return C.POST_NO_CONFIRM
     url = self.get_page_by_name("chat").get_url(jid_)
     self.http_redirect(request, url)
--- a/libervia/web/server/restricted_bridge.py	Sun Dec 10 18:33:00 2023 +0100
+++ b/libervia/web/server/restricted_bridge.py	Mon Dec 11 00:43:06 2023 +0100
@@ -47,6 +47,17 @@
             "action_launch", callback_id, data_s, profile
         )
 
+    async def bookmarks_list(
+        self,
+        type_: str,
+        storage_location: str,
+        profile: str
+    ):
+        self.no_service_profile(profile)
+        return await self.host.bridge_call(
+            "bookmarks_list", type_, storage_location, profile
+        )
+
     async def call_start(self, entity: str, call_data_s: str, profile: str) -> None:
         self.no_service_profile(profile)
         return await self.host.bridge_call(