From 15ad700b223fd0f2e6c8ddc9f692f5fbfa029586 Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 14 May 2026 11:42:45 +0200 Subject: [PATCH] plugin XEP-0402: Fetch bookmarks on startup and handle autojoin. --- libervia/backend/plugins/plugin_xep_0402.py | 30 ++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/libervia/backend/plugins/plugin_xep_0402.py b/libervia/backend/plugins/plugin_xep_0402.py index 46b90538..fddfaaca 100644 --- a/libervia/backend/plugins/plugin_xep_0402.py +++ b/libervia/backend/plugins/plugin_xep_0402.py @@ -118,7 +118,7 @@ class Conference(BaseModel): conference_elt = child_conference_elt kwargs = {} if conference_elt.hasAttribute("autojoin"): - kwargs["autojoin"] = conference_elt["autojoin"] == "true" + kwargs["autojoin"] = C.bool(conference_elt["autojoin"]) if conference_elt.hasAttribute("name"): kwargs["name"] = conference_elt["name"] nick_elt = next(conference_elt.elements(NS_BOOKMARKS2, "nick"), None) @@ -227,6 +227,34 @@ class XEP_0402: pep.add_pep_event(None, NS_BOOKMARKS2, self._on_bookmark_event) host.register_namespace("bookmarks2", NS_BOOKMARKS2) + async def profile_connected(self, client: SatXMPPEntity) -> None: + """Fetch bookmarks and autojoin in background.""" + defer.ensureDeferred(self._fetch_and_process_bookmarks(client)) + + async def _fetch_and_process_bookmarks(self, client: SatXMPPEntity) -> None: + """Fetch bookmarks and process join/leave for autojoin rooms. + + @param client: Client session. + """ + try: + bookmarks = await self.list(client) + except Exception: + log.exception(f"[{client.profile}] Failed to retrieve bookmarks on startup") + return + for room_jid, conference in bookmarks.items(): + try: + if conference.autojoin: + await self._muc.join( + client, + room_jid, + conference.nick, + {"password": conference.password}, + ) + except Exception: + log.exception( + f"[{client.profile}] Failed to process autojoin for {room_jid}" + ) + async def _on_bookmark_event( self, items_events: pubsub.ItemsEvent, profile: str ) -> None: