Additional modifications concerning to PubSub.

This commit is contained in:
Schimon Jehudah, Adv. 2024-11-19 17:40:33 +02:00
parent dac0c771dd
commit 412acc7cbe

View file

@ -970,7 +970,8 @@ class XmppClient(slixmpp.ClientXMPP):
.format(function_name, jid_full)) .format(function_name, jid_full))
jid_bare = session['from'].bare jid_bare = session['from'].bare
chat_type = await XmppUtilities.get_chat_type(self, jid_bare) chat_type = await XmppUtilities.get_chat_type(self, jid_bare)
if XmppUtilities.is_access(self, jid, chat_type): pubsubs = await XmppPubsub.get_pubsub_services(self)
if XmppUtilities.is_access(self, jid, chat_type) and pubsubs:
values = payload['values'] values = payload['values']
form = self['xep_0004'].make_form('form', 'Publish') form = self['xep_0004'].make_form('form', 'Publish')
form['instructions'] = ('Choose a PubSub Jabber ID and verify ' form['instructions'] = ('Choose a PubSub Jabber ID and verify '
@ -995,7 +996,6 @@ class XmppClient(slixmpp.ClientXMPP):
conferences = await XmppBookmark.get_bookmarks(self) conferences = await XmppBookmark.get_bookmarks(self)
for conference in conferences: for conference in conferences:
jids.extend([conference['jid']]) jids.extend([conference['jid']])
pubsubs = await XmppPubsub.get_pubsub_services(self)
for pubsub in pubsubs: for pubsub in pubsubs:
jids.extend([pubsub['jid']]) jids.extend([pubsub['jid']])
for jid_bare in sorted(jids): for jid_bare in sorted(jids):
@ -1018,9 +1018,9 @@ class XmppClient(slixmpp.ClientXMPP):
ftype='list-single', ftype='list-single',
label='PubSub', label='PubSub',
required=True, required=True,
value=self.boundjid.bare,
var='jid') var='jid')
options.addOption(self.boundjid.bare, self.boundjid.bare) for pubsub in pubsubs:
options.addOption(pubsub['jid'], pubsub['jid'])
iq = await self['xep_0030'].get_items(jid=self.boundjid.domain) iq = await self['xep_0030'].get_items(jid=self.boundjid.domain)
items = iq['disco_items']['items'] items = iq['disco_items']['items']
for item in items: for item in items:
@ -1068,9 +1068,14 @@ class XmppClient(slixmpp.ClientXMPP):
elif chat_type == 'groupchat': elif chat_type == 'groupchat':
text_warn = ('This resource is restricted to moderators of {}.' text_warn = ('This resource is restricted to moderators of {}.'
.format(jid_bare)) .format(jid_bare))
elif not pubsubs:
text_warn = 'No PubSub services were found on this server.'
else: else:
text_warn = 'This resource is restricted.' text_warn = 'This resource is restricted.'
session['has_next'] = False
session['next'] = None
session['notes'] = [['warn', text_warn]] session['notes'] = [['warn', text_warn]]
session['payload'] = None
return session return session
async def _handle_publish_db_preview(self, payload, session): async def _handle_publish_db_preview(self, payload, session):
@ -1739,6 +1744,7 @@ class XmppClient(slixmpp.ClientXMPP):
# FIXME # FIXME
# TODO Restore document export. Copy code from Slixprint.
async def _handle_recent_select(self, payload, session): async def _handle_recent_select(self, payload, session):
jid_full = session['from'].full jid_full = session['from'].full
function_name = sys._getframe().f_code.co_name function_name = sys._getframe().f_code.co_name
@ -3145,14 +3151,12 @@ class XmppClient(slixmpp.ClientXMPP):
# jid_bare = self.boundjid.bare # jid_bare = self.boundjid.bare
# enabled_state = Config.get_setting_value(self, jid_bare, 'enabled') # enabled_state = Config.get_setting_value(self, jid_bare, 'enabled')
results = await XmppPubsub.get_pubsub_services(self)
options = form.add_field(desc='Select a PubSub service.', options = form.add_field(desc='Select a PubSub service.',
ftype='list-single', ftype='list-single',
label='Jabber ID', label='Jabber ID',
value=self.boundjid.bare, value=self.boundjid.bare,
var='jid') var='jid')
for result in results + [{'jid' : self.boundjid.bare, for result in await XmppPubsub.get_pubsub_services(self):
'name' : self.alias}]:
name = result['name'] name = result['name']
jid_bare = result['jid'] jid_bare = result['jid']
options.addOption(name, jid_bare) options.addOption(name, jid_bare)
@ -3171,8 +3175,7 @@ class XmppClient(slixmpp.ClientXMPP):
# enabled_state = Config.get_setting_value(self, jid_bare, 'enabled') # enabled_state = Config.get_setting_value(self, jid_bare, 'enabled')
results = await XmppPubsub.get_pubsub_services(self) results = await XmppPubsub.get_pubsub_services(self)
for result in results + [{'jid' : self.boundjid.bare, for result in await XmppPubsub.get_pubsub_services(self):
'name' : self.alias}]:
jid_bare = result['jid'] jid_bare = result['jid']
name = result['name'] name = result['name']
enabled_state = Config.get_setting_value( enabled_state = Config.get_setting_value(