plugin XEP-0402: Fetch bookmarks on startup and handle autojoin.
This commit is contained in:
parent
dce577bf3a
commit
15ad700b22
1 changed files with 29 additions and 1 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue