From e4237f972f9fced9a6260f5e0c105f14d4580668 Mon Sep 17 00:00:00 2001 From: Schimon Jehudah Date: Mon, 13 May 2024 07:28:12 +0000 Subject: [PATCH] Fix handling of PubSub of own Jabber ID --- slixfeed/action.py | 29 ++++++++++++++++++++++------- slixfeed/sqlite.py | 4 ++-- slixfeed/version.py | 4 ++-- slixfeed/xmpp/client.py | 8 +++++--- slixfeed/xmpp/muc.py | 9 +++++++-- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/slixfeed/action.py b/slixfeed/action.py index 320071c..0f15541 100644 --- a/slixfeed/action.py +++ b/slixfeed/action.py @@ -258,6 +258,19 @@ async def xmpp_pubsub_send_selected_entry(self, jid_bare, jid_file, node_id, ent async def xmpp_pubsub_send_unread_items(self, jid_bare): + """ + + Parameters + ---------- + jid_bare : TYPE + Bare Jabber ID. + + Returns + ------- + report : dict + URL and Number of processed entries. + + """ function_name = sys._getframe().f_code.co_name logger.debug('{}: jid_bare: {}'.format(function_name, jid_bare)) jid_file = jid_bare.replace('/', '_') @@ -266,19 +279,23 @@ async def xmpp_pubsub_send_unread_items(self, jid_bare): subscriptions = sqlite.get_active_feeds_url(db_file) for url in subscriptions: url = url[0] + # feed_id = sqlite.get_feed_id(db_file, url) + # feed_id = feed_id[0] + # feed_properties = sqlite.get_feed_properties(db_file, feed_id) + feed_id = sqlite.get_feed_id(db_file, url) + feed_id = feed_id[0] + + # Publish to node 'urn:xmpp:microblog:0' for own JID + # Publish to node based on feed identifier for PubSub service. + if jid_bare == self.boundjid.bare: node_id = 'urn:xmpp:microblog:0' node_subtitle = None node_title = None else: - # feed_id = sqlite.get_feed_id(db_file, url) - # feed_id = feed_id[0] - # feed_properties = sqlite.get_feed_properties(db_file, feed_id) # node_id = feed_properties[2] # node_title = feed_properties[3] # node_subtitle = feed_properties[5] - feed_id = sqlite.get_feed_id(db_file, url) - feed_id = feed_id[0] node_id = sqlite.get_feed_identifier(db_file, feed_id) node_id = node_id[0] node_title = sqlite.get_feed_title(db_file, feed_id) @@ -290,8 +307,6 @@ async def xmpp_pubsub_send_unread_items(self, jid_bare): self, jid_bare, node_id, xep, node_title, node_subtitle) await XmppIQ.send(self, iq_create_node) entries = sqlite.get_unread_entries_of_feed(db_file, feed_id) - print('xmpp_pubsub_send_unread_items',jid_bare) - print(node_id) report[url] = len(entries) for entry in entries: feed_entry = pack_entry_into_dict(db_file, entry) diff --git a/slixfeed/sqlite.py b/slixfeed/sqlite.py index 4833798..af1799f 100644 --- a/slixfeed/sqlite.py +++ b/slixfeed/sqlite.py @@ -1634,8 +1634,8 @@ def get_unread_entries_of_feed(db_file, feed_id): """ ) par = (feed_id,) - count = cur.execute(sql, par).fetchall() - return count + result = cur.execute(sql, par).fetchall() + return result def get_number_of_unread_entries_by_feed(db_file, feed_id): diff --git a/slixfeed/version.py b/slixfeed/version.py index 3d5447b..4b1da66 100644 --- a/slixfeed/version.py +++ b/slixfeed/version.py @@ -1,2 +1,2 @@ -__version__ = '0.1.61' -__version_info__ = (0, 1, 61) +__version__ = '0.1.62' +__version_info__ = (0, 1, 62) diff --git a/slixfeed/xmpp/client.py b/slixfeed/xmpp/client.py index 2eb056a..fb6e180 100644 --- a/slixfeed/xmpp/client.py +++ b/slixfeed/xmpp/client.py @@ -305,8 +305,6 @@ class Slixfeed(slixmpp.ClientXMPP): await self['xep_0115'].update_caps() # self.send_presence() await self.get_roster() - bookmarks = await XmppBookmark.get_bookmarks(self) - await action.xmpp_muc_autojoin(self, bookmarks) results = await XmppPubsub.get_pubsub_services(self) for result in results + [{'jid' : self.boundjid.bare, 'name' : self.alias}]: @@ -317,6 +315,10 @@ class Slixfeed(slixmpp.ClientXMPP): await task.start_tasks_xmpp_pubsub(self, jid_bare) # XmppCommand.adhoc_commands(self) # self.service_reactions() + bookmarks = await XmppBookmark.get_bookmarks(self) + print('iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii') + await action.xmpp_muc_autojoin(self, bookmarks) + print('ooooooooooooooooooooooooooooooooo') task.task_ping(self) time_end = time.time() difference = time_end - time_begin @@ -3124,7 +3126,7 @@ class Slixfeed(slixmpp.ClientXMPP): form.add_field(var='jid', ftype='hidden', value=jid) - session['has_next'] = False + session['has_next'] = True session['next'] = self._handle_nodes_action session['allow_prev'] = True session['payload'] = form diff --git a/slixfeed/xmpp/muc.py b/slixfeed/xmpp/muc.py index b70f2c2..ffec5ea 100644 --- a/slixfeed/xmpp/muc.py +++ b/slixfeed/xmpp/muc.py @@ -50,22 +50,27 @@ class XmppGroupchat: await self.plugin['xep_0045'].join_muc_wait(jid, alias, presence_options = {"pfrom" : jid_from}, - password=password) + password=password, + timeout=30) + result = 'joined ' + jid except IqError as e: logging.error('Error XmppIQ') logging.error(str(e)) logging.error(jid) + result = 'error' except IqTimeout as e: logging.error('Timeout XmppIQ') logging.error(str(e)) logging.error(jid) + result = 'timeout' except PresenceError as e: logging.error('Error Presence') logging.error(str(e)) if (e.condition == 'forbidden' and e.presence['error']['code'] == '403'): logging.warning('{} is banned from {}'.format(self.alias, jid)) - return 'ban' + result = 'ban' + return result def leave(self, jid):