From 08001eebf838cbda91f271d05c8733fe352ea588 Mon Sep 17 00:00:00 2001 From: Schimon Jehudah Date: Thu, 28 Dec 2023 16:22:32 +0000 Subject: [PATCH] Add __init__.py and split muc.py into bookmark.py --- slixfeed/__init__.py | 0 slixfeed/xmpp/bookmark.py | 60 +++++++++++++++++++++++++++++++++++++++ slixfeed/xmpp/muc.py | 52 ++------------------------------- 3 files changed, 63 insertions(+), 49 deletions(-) create mode 100644 slixfeed/__init__.py create mode 100644 slixfeed/xmpp/bookmark.py diff --git a/slixfeed/__init__.py b/slixfeed/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/slixfeed/xmpp/bookmark.py b/slixfeed/xmpp/bookmark.py new file mode 100644 index 0000000..2eb3749 --- /dev/null +++ b/slixfeed/xmpp/bookmark.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" + +TODO + +1) Function to list bookmarks + +""" + + +from slixmpp.plugins.xep_0048.stanza import Bookmarks + + +async def add(self, muc_jid): + result = await self.plugin['xep_0048'].get_bookmarks() + bookmarks = result["private"]["bookmarks"] + conferences = bookmarks["conferences"] + mucs = [] + for conference in conferences: + jid = conference["jid"] + mucs.extend([jid]) + if muc_jid not in mucs: + bookmarks = Bookmarks() + mucs.extend([muc_jid]) + for muc in mucs: + bookmarks.add_conference( + muc, + self.nick, + autojoin=True + ) + await self.plugin['xep_0048'].set_bookmarks(bookmarks) + # bookmarks = Bookmarks() + # await self.plugin['xep_0048'].set_bookmarks(bookmarks) + # print(await self.plugin['xep_0048'].get_bookmarks()) + + # bm = BookmarkStorage() + # bm.conferences.append(Conference(muc_jid, autojoin=True, nick=self.nick)) + # await self['xep_0402'].publish(bm) + + +async def remove(self, muc_jid): + result = await self.plugin['xep_0048'].get_bookmarks() + bookmarks = result["private"]["bookmarks"] + conferences = bookmarks["conferences"] + mucs = [] + for conference in conferences: + jid = conference["jid"] + mucs.extend([jid]) + if muc_jid in mucs: + bookmarks = Bookmarks() + mucs.remove(muc_jid) + for muc in mucs: + bookmarks.add_conference( + muc, + self.nick, + autojoin=True + ) + await self.plugin['xep_0048'].set_bookmarks(bookmarks) diff --git a/slixfeed/xmpp/muc.py b/slixfeed/xmpp/muc.py index bcbb012..62727d0 100644 --- a/slixfeed/xmpp/muc.py +++ b/slixfeed/xmpp/muc.py @@ -13,7 +13,7 @@ TODO """ -from slixmpp.plugins.xep_0048.stanza import Bookmarks +import slixfeed.xmpp.bookmark as bookmark async def join_groupchat(self, inviter, muc_jid): # token = await initdb( @@ -42,7 +42,7 @@ async def join_groupchat(self, inviter, muc_jid): # If a room password is needed, use: # password=the_room_password, ) - await self.add_groupchat_to_bookmarks(muc_jid) + await bookmark.add(self, muc_jid) messages = [ "Greetings!", "I'm {}, the news anchor.".format(self.nick), @@ -59,33 +59,6 @@ async def join_groupchat(self, inviter, muc_jid): ) -async def add_groupchat_to_bookmarks(self, muc_jid): - result = await self.plugin['xep_0048'].get_bookmarks() - bookmarks = result["private"]["bookmarks"] - conferences = bookmarks["conferences"] - mucs = [] - for conference in conferences: - jid = conference["jid"] - mucs.extend([jid]) - if muc_jid not in mucs: - bookmarks = Bookmarks() - mucs.extend([muc_jid]) - for muc in mucs: - bookmarks.add_conference( - muc, - self.nick, - autojoin=True - ) - await self.plugin['xep_0048'].set_bookmarks(bookmarks) - # bookmarks = Bookmarks() - # await self.plugin['xep_0048'].set_bookmarks(bookmarks) - # print(await self.plugin['xep_0048'].get_bookmarks()) - - # bm = BookmarkStorage() - # bm.conferences.append(Conference(muc_jid, autojoin=True, nick=self.nick)) - # await self['xep_0402'].publish(bm) - - async def close_groupchat(self, muc_jid): messages = [ "Whenever you need an RSS service again, " @@ -99,7 +72,7 @@ async def close_groupchat(self, muc_jid): mbody=message, mtype="groupchat" ) - await self.remove_groupchat_from_bookmarks(muc_jid) + await bookmark.remove(self, muc_jid) self.plugin['xep_0045'].leave_muc( muc_jid, self.nick, @@ -107,22 +80,3 @@ async def close_groupchat(self, muc_jid): self.boundjid.bare ) - -async def remove_groupchat_from_bookmarks(self, muc_jid): - result = await self.plugin['xep_0048'].get_bookmarks() - bookmarks = result["private"]["bookmarks"] - conferences = bookmarks["conferences"] - mucs = [] - for conference in conferences: - jid = conference["jid"] - mucs.extend([jid]) - if muc_jid in mucs: - bookmarks = Bookmarks() - mucs.remove(muc_jid) - for muc in mucs: - bookmarks.add_conference( - muc, - self.nick, - autojoin=True - ) - await self.plugin['xep_0048'].set_bookmarks(bookmarks)