PubSub: Remove code which publishes to self PEP node.

This commit is contained in:
Schimon Jehudah, Adv. 2024-11-19 16:35:09 +02:00
parent 79b80b1698
commit 8181c9dc74
2 changed files with 38 additions and 83 deletions

View file

@ -400,20 +400,7 @@ class XmppClient(slixmpp.ClientXMPP):
print('POSIX sockets: Initiating IPC server...')
self.ipc = asyncio.create_task(XmppIpcServer.ipc(self))
jids_of_pubsub = await XmppPubsub.get_pubsub_services(self)
for jid_bare in jids_of_pubsub:
jid_bare['type'] = 'pubsub'
# NOTE Do you need 'name' too, or only 'jid'?
#jids_of_roster = []
#for jid_bare in self.client_roster:
# jids_of_roster.append({'jid' : jid_bare,
# 'name' : '',
# 'type' : 'pep'})
jid_of_slixfeed = [{'jid' : self.boundjid.bare,
'name' : self.alias,
'type' : 'pep'}]
#for result in jids_of_pubsub + jids_of_roster + jid_of_slixfeed:
for result in jids_of_pubsub + jid_of_slixfeed:
for result in await XmppPubsub.get_pubsub_services(self):
jid_bare = result['jid']
if jid_bare not in self.settings:
db_file = config.get_pathname_to_database(jid_bare)
@ -431,8 +418,7 @@ class XmppClient(slixmpp.ClientXMPP):
asyncio.create_task(FeedTask.loop_task(self, jid_bare))
#await asyncio.sleep(10)
print('publish task for {}'.format(jid_bare))
publish_type = result['type']
asyncio.create_task(XmppPubsubTask.loop_task(self, jid_bare, publish_type)),
asyncio.create_task(XmppPubsubTask.loop_task(self, jid_bare)),
print('End')
time_end = time.time()
@ -1057,6 +1043,8 @@ class XmppClient(slixmpp.ClientXMPP):
form.add_field(desc='Enter a node to publish to.',
ftype='text-single',
label='Node',
required=True,
value='Slixfeed',
var='node')
# options = form.add_field(desc='Select XMPP Extension Protocol.',
# ftype='list-single',
@ -1065,7 +1053,7 @@ class XmppClient(slixmpp.ClientXMPP):
# value='0060',
# var='xep')
# options.addOption('XEP-0060: Publish-Subscribe', '0060')
# options.addOption('XEP-0277: Microblogging over XMPP', '0277')
# options.addOption('XEP-0277: Journaling over XMPP', '0277')
# options.addOption('XEP-0472: Pubsub Social Feed', '0472')
session['payload'] = form
session['allow_prev'] = True
@ -1108,11 +1096,6 @@ class XmppClient(slixmpp.ClientXMPP):
jid_bare = values['jid_bare']
node = values['node']
# xep = values['xep']
if not node:
if jid == self.boundjid.bare:
node = 'urn:xmpp:microblog:0'
else:
node = 'slixfeed'
form = self['xep_0004'].make_form('form', 'Publish')
form.add_field(var='node',
@ -1216,11 +1199,7 @@ class XmppClient(slixmpp.ClientXMPP):
node = values['node']
url = values['url']
# xep = values['xep']
if not node:
if jid == self.boundjid.bare:
node = 'urn:xmpp:microblog:0'
else:
node = Url.get_hostname(url)
if not node: node = Url.get_hostname(url)
form = self['xep_0004'].make_form('form', 'Publish')
while True:
result = await fetch.http(url)
@ -3183,7 +3162,7 @@ class XmppClient(slixmpp.ClientXMPP):
form = self['xep_0004'].make_form('form', 'PubSub')
form['instructions'] = ('Designate Publish-Subscribe services '
'for IoT updates, news publishing, '
'and even for microblogging on '
'and even for publishing on '
'platforms such as Libervia and Movim.')
form.add_field(desc='Select PubSub services to designate.',
ftype='fixed',

View file

@ -260,20 +260,9 @@ class XmppPubsubAction:
function_name = sys._getframe().f_code.co_name
logger.debug('{}: jid_bare: {}'.format(function_name, jid_bare))
db_file = config.get_pathname_to_database(jid_bare)
report = {}
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_by_entry_index(db_file, entry_id)
feed_id = feed_id[0]
node_id, node_title, node_subtitle = sqlite.get_feed_properties(db_file, feed_id)
print('THIS IS A TEST')
print(node_id)
print(node_title)
print(node_subtitle)
print('THIS IS A TEST')
feed_id = sqlite.get_feed_id_by_entry_index(db_file, entry_id)
feed_id = feed_id[0]
node_id, node_title, node_subtitle = sqlite.get_feed_properties(db_file, feed_id)
xep = None
iq_create_node = XmppPubsub.create_node(
self, jid_bare, node_id, xep, node_title, node_subtitle)
@ -283,25 +272,23 @@ class XmppPubsubAction:
print(node_id)
entry_dict = Feed.pack_entry_into_dict(db_file, entry)
node_item = Feed.create_rfc4287_entry(entry_dict)
entry_url = entry_dict['link']
item_id = Utilities.hash_url_to_md5(entry_url)
item_id = Utilities.hash_url_to_md5(entry_dict['link'])
iq_create_entry = XmppPubsub.create_entry(
self, jid_bare, node_id, item_id, node_item)
await XmppIQ.send(self, iq_create_entry)
await sqlite.mark_as_read(db_file, entry_id)
report = entry_url
return report
# NOTE This value is returned for the sake of testing
return entry_dict['link']
async def send_unread_items(self, jid_bare, publish_type):
async def send_unread_items(self, jid_bare):
"""
Parameters
----------
jid_bare : str
Bare Jabber ID.
publish_type : str
To which type of PubSub ('pep' or 'pubsub').
Returns
-------
@ -321,40 +308,29 @@ class XmppPubsubAction:
# 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.
match publish_type:
# XEP-0163: Personal Eventing Protocol
# 2.2 One Publisher Per Node¶
# The owner-publisher for every node is the bare JID of the account owner.
case 'pep':
node_id = 'urn:xmpp:microblog:0'
node_subtitle = None
node_title = None
case 'pubsub':
# node_id = feed_properties[2]
# node_title = feed_properties[3]
# node_subtitle = feed_properties[5]
node_id = sqlite.get_feed_identifier(db_file, feed_id)
node_id = node_id[0]
if not node_id:
counter = 0
while True:
identifier = String.generate_identifier(url, counter)
if sqlite.check_identifier_exist(db_file, identifier):
counter += 1
else:
break
await sqlite.update_feed_identifier(db_file, feed_id, identifier)
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)
node_title = node_title[0]
node_subtitle = sqlite.get_feed_subtitle(db_file, feed_id)
node_subtitle = node_subtitle[0]
print ([jid_bare, publish_type, node_id])
# node_id = feed_properties[2]
# node_title = feed_properties[3]
# node_subtitle = feed_properties[5]
node_id = sqlite.get_feed_identifier(db_file, feed_id)
node_id = node_id[0]
if not node_id:
counter = 0
while True:
identifier = String.generate_identifier(url, counter)
if sqlite.check_identifier_exist(db_file, identifier):
counter += 1
else:
break
await sqlite.update_feed_identifier(db_file, feed_id, identifier)
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)
node_title = node_title[0]
node_subtitle = sqlite.get_feed_subtitle(db_file, feed_id)
node_subtitle = node_subtitle[0]
xep = None
#node_exist = await XmppPubsub.get_node_configuration(self, jid_bare, node_id)
nodes = await XmppPubsub.get_nodes(self, jid_bare)
@ -395,7 +371,7 @@ class XmppPubsubAction:
class XmppPubsubTask:
async def loop_task(self, jid_bare, publish_type):
async def loop_task(self, jid_bare):
db_file = config.get_pathname_to_database(jid_bare)
if jid_bare not in self.settings:
Config.add_settings_jid(self, jid_bare, db_file)
@ -412,7 +388,7 @@ class XmppPubsubTask:
.format(jid_bare))
logger.info('Starting tasks "publish" for JID {}'.format(jid_bare))
self.task_manager[jid_bare]['publish'] = asyncio.create_task(
XmppPubsubAction.send_unread_items(self, jid_bare, publish_type))
XmppPubsubAction.send_unread_items(self, jid_bare))
await asyncio.sleep(60 * 180)