Python : Fix display of PEP and PubSub.
This commit is contained in:
parent
92b4f5d6d2
commit
899f87865d
2 changed files with 242 additions and 215 deletions
|
@ -198,6 +198,12 @@ label,
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#action > a,
|
||||||
|
#action-bar > a {
|
||||||
|
padding-left: 1em;
|
||||||
|
padding-right: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
#number-of-pages .inactive {
|
#number-of-pages .inactive {
|
||||||
background: #7a7a7a;
|
background: #7a7a7a;
|
||||||
}
|
}
|
||||||
|
|
337
fasi.py
337
fasi.py
|
@ -91,7 +91,7 @@ class HttpInstance:
|
||||||
|
|
||||||
#try:
|
#try:
|
||||||
if True:
|
if True:
|
||||||
exception = jid_detail = messages_10 = note = node_title = \
|
exception = jid_vcard = messages_10 = note = node_title = \
|
||||||
node_note = number_of_pages = page_number = previous = \
|
node_note = number_of_pages = page_number = previous = \
|
||||||
selection = services_sorted = subject = None
|
selection = services_sorted = subject = None
|
||||||
node_name = 'urn:xmpp:microblog:0'
|
node_name = 'urn:xmpp:microblog:0'
|
||||||
|
@ -102,14 +102,23 @@ class HttpInstance:
|
||||||
filename = 'details/{}.toml'.format(jid_bare)
|
filename = 'details/{}.toml'.format(jid_bare)
|
||||||
if os.path.exists(filename) and os.path.getsize(filename) > 0:
|
if os.path.exists(filename) and os.path.getsize(filename) > 0:
|
||||||
jid_details = Data.open_file_toml(filename)
|
jid_details = Data.open_file_toml(filename)
|
||||||
|
else:
|
||||||
|
jid_details = await FileUtilities.cache_jid_data(
|
||||||
|
jabber_id, password, jid_bare, node_name, alias=alias)
|
||||||
|
|
||||||
action = jid_details['action']
|
action = jid_details['action']
|
||||||
count = jid_details['count']
|
count = jid_details['count']
|
||||||
instance = jid_details['instance']
|
instance = jid_details['instance']
|
||||||
|
items = jid_details['items']
|
||||||
jid_info = {
|
jid_info = {
|
||||||
'error' : jid_details['error'],
|
'error' : jid_details['error'],
|
||||||
'text' : jid_details['error_text'],
|
'text' : jid_details['error_text'],
|
||||||
'condition' : jid_details['error_condition']}
|
'condition' : jid_details['error_condition']}
|
||||||
jid_kind = jid_details['kind']
|
jid_kind = jid_details['kind']
|
||||||
|
jid_vcard = {
|
||||||
|
'name' : jid_details['name'],
|
||||||
|
'note' : jid_details['note'],
|
||||||
|
'type' : jid_details['image_type']}
|
||||||
link_href = jid_details['link_href']
|
link_href = jid_details['link_href']
|
||||||
messages = jid_details['messages']
|
messages = jid_details['messages']
|
||||||
nodes = jid_details['nodes']
|
nodes = jid_details['nodes']
|
||||||
|
@ -117,15 +126,6 @@ class HttpInstance:
|
||||||
title = jid_details['name']
|
title = jid_details['name']
|
||||||
xmpp_uri = jid_details['uri']
|
xmpp_uri = jid_details['uri']
|
||||||
view_href = jid_details['view_href']
|
view_href = jid_details['view_href']
|
||||||
else:
|
|
||||||
jid_data = await FileUtilities.cache_jid_data(jabber_id, password, jid_bare, node_name, alias=alias)
|
|
||||||
count = jid_data['count']
|
|
||||||
jid_detail = jid_data['jid_detail']
|
|
||||||
jid_info = jid_data['jid_info']
|
|
||||||
jid_kind = jid_data['jid_kind']
|
|
||||||
jid_details = jid_data['jid_details']
|
|
||||||
note = jid_data['note']
|
|
||||||
title = jid_data['title']
|
|
||||||
|
|
||||||
# Group chat messages
|
# Group chat messages
|
||||||
# NOTE TODO
|
# NOTE TODO
|
||||||
|
@ -149,7 +149,7 @@ class HttpInstance:
|
||||||
jid_bare, jid_info, jid_kind, node_name)
|
jid_bare, jid_info, jid_kind, node_name)
|
||||||
|
|
||||||
# Graphic files
|
# Graphic files
|
||||||
filename, filepath, filetype, selection = FileUtilities.handle_photo(jid_bare, jid_detail)
|
filename, filepath, filetype, selection = FileUtilities.handle_photo(jid_bare, jid_vcard)
|
||||||
|
|
||||||
#except Exception as e:
|
#except Exception as e:
|
||||||
else:
|
else:
|
||||||
|
@ -157,7 +157,9 @@ class HttpInstance:
|
||||||
action = 'Error'
|
action = 'Error'
|
||||||
title = 'Slixmpp error'
|
title = 'Slixmpp error'
|
||||||
xmpp_uri = note = jid
|
xmpp_uri = note = jid
|
||||||
filename = jid_bare = link_href = link_tex = node_note = node_title = number_of_pages = page_number = previous = selection = services = services_sorted = url = None
|
filename = jid_bare = link_href = link_tex = node_note = \
|
||||||
|
node_title = number_of_pages = page_number = previous = \
|
||||||
|
selection = services = services_sorted = url = None
|
||||||
|
|
||||||
#if title == 'remote-server-timeout':
|
#if title == 'remote-server-timeout':
|
||||||
# raise HTTPException(status_code=408, detail='remote-server-timeout')
|
# raise HTTPException(status_code=408, detail='remote-server-timeout')
|
||||||
|
@ -201,25 +203,35 @@ class HttpInstance:
|
||||||
|
|
||||||
#try:
|
#try:
|
||||||
if True:
|
if True:
|
||||||
entries = exception = jid_detail = note = node_note = \
|
entries = []
|
||||||
number_of_pages = page_number = previous = selection = \
|
exception = jid_vcard = note = node_note = number_of_pages = \
|
||||||
services_sorted = None
|
page_number = previous = selection = services_sorted = None
|
||||||
node_title = node_name
|
node_title = node_name
|
||||||
link_href = 'xmpp:{}?pubsub;node={};action=subscribe'.format(jid_bare, node_name)
|
link_href = 'xmpp:{}?pubsub;node={};action=subscribe'.format(
|
||||||
|
jid_bare, node_name)
|
||||||
link_text = 'Subscribe'
|
link_text = 'Subscribe'
|
||||||
xmpp_uri = '{}?;node={}'.format(jid_bare, node_name)
|
xmpp_uri = '{}?;node={}'.format(jid_bare, node_name)
|
||||||
|
|
||||||
filename = 'details/{}.toml'.format(jid_bare)
|
filename = 'details/{}.toml'.format(jid_bare)
|
||||||
if os.path.exists(filename) and os.path.getsize(filename) > 0:
|
if os.path.exists(filename) and os.path.getsize(filename) > 0:
|
||||||
jid_details = Data.open_file_toml(filename)
|
jid_details = Data.open_file_toml(filename)
|
||||||
|
else:
|
||||||
|
jid_details = await FileUtilities.cache_jid_data(
|
||||||
|
jabber_id, password, jid_bare, node_name, item_id)
|
||||||
|
|
||||||
action = jid_details['action']
|
action = jid_details['action']
|
||||||
count = jid_details['count']
|
count = jid_details['count']
|
||||||
instance = jid_details['instance']
|
instance = jid_details['instance']
|
||||||
|
items = jid_details['items']
|
||||||
jid_info = {
|
jid_info = {
|
||||||
'error' : jid_details['error'],
|
'error' : jid_details['error'],
|
||||||
'text' : jid_details['error_text'],
|
'text' : jid_details['error_text'],
|
||||||
'condition' : jid_details['error_condition']}
|
'condition' : jid_details['error_condition']}
|
||||||
jid_kind = jid_details['kind']
|
jid_kind = jid_details['kind']
|
||||||
|
jid_vcard = {
|
||||||
|
'name' : jid_details['name'],
|
||||||
|
'note' : jid_details['note'],
|
||||||
|
'type' : jid_details['image_type']}
|
||||||
link_href = jid_details['link_href']
|
link_href = jid_details['link_href']
|
||||||
messages = jid_details['messages']
|
messages = jid_details['messages']
|
||||||
nodes = jid_details['nodes']
|
nodes = jid_details['nodes']
|
||||||
|
@ -227,83 +239,87 @@ class HttpInstance:
|
||||||
title = jid_details['name']
|
title = jid_details['name']
|
||||||
xmpp_uri = jid_details['uri']
|
xmpp_uri = jid_details['uri']
|
||||||
view_href = jid_details['view_href']
|
view_href = jid_details['view_href']
|
||||||
|
|
||||||
|
xmpp_instance = XmppInstance(jabber_id, password, jid_bare)
|
||||||
|
xmpp_instance.connect()
|
||||||
|
|
||||||
|
# Node item IDs
|
||||||
if node_name not in nodes:
|
if node_name not in nodes:
|
||||||
node_item_ids = await XmppXep0060.get_node_item_ids(xmpp_instance, jid_bare, node_name)
|
nodes[node_name] = {}
|
||||||
if isinstance(node_item_ids, stanza.iq.Iq):
|
node_item_ids = await XmppXep0060.get_node_item_ids(
|
||||||
nodes[node_name] = node_item_ids['disco_items']['items']
|
xmpp_instance, jid_bare, node_name)
|
||||||
else:
|
#node_item_ids = await XmppUtilities.get_item_ids_of_node(
|
||||||
jid_data = await FileUtilities.cache_jid_data(jabber_id, password, jid_bare, node_name, item_id)
|
# jabber_id, password, jid_bare, node_name, nodes)
|
||||||
count = jid_data['count']
|
if isinstance(node_item_ids['iq'], stanza.iq.Iq):
|
||||||
jid_detail = jid_data['jid_detail']
|
nodes[node_name]['count'] = len(node_item_ids['iq']['disco_items']['items'])
|
||||||
jid_info = jid_data['jid_info']
|
nodes[node_name]['item_ids'] = []
|
||||||
jid_kind = jid_data['jid_kind']
|
for item in node_item_ids['iq']['disco_items']['items']:
|
||||||
jid_details = jid_data['jid_details']
|
nodes[node_name]['item_ids'].append(
|
||||||
note = jid_data['note']
|
[item[0] or '', item[1] or '', item[2] or ''])
|
||||||
title = jid_data['title']
|
|
||||||
|
|
||||||
# Node items
|
# Node items
|
||||||
# NOTE TODO
|
if item_id:
|
||||||
# page_number = request.query_params.get('page', '')
|
previous = True
|
||||||
# if page_number:
|
node_items = await XmppXep0060.get_node_items(
|
||||||
# try:
|
xmpp_instance, jid_bare, node_name, item_ids=[item_id])
|
||||||
# page_number = int(page_number)
|
else:
|
||||||
# ix = (page_number -1) * 10
|
item_ids = []
|
||||||
# except:
|
for item in nodes[node_name]['item_ids']:
|
||||||
# ix = 0
|
item_ids.append(item[2])
|
||||||
# page_number = 1
|
# NOTE Consider to neglect the reversal of order, because, then, items can be found at the same page.
|
||||||
# else:
|
item_ids.reverse()
|
||||||
# ix = 0
|
page_number = request.query_params.get('page', '')
|
||||||
# page_number = 1
|
if page_number:
|
||||||
# item_ids_10 = item_ids[ix:][:10]
|
try:
|
||||||
|
page_number = int(page_number)
|
||||||
# if item_id:
|
ix = (page_number -1) * 10
|
||||||
# previous = True
|
except:
|
||||||
# node_items = await XmppXep0060.get_node_items(xmpp_instance, jid_bare, node_name, item_ids=[item_id])
|
ix = 0
|
||||||
# else:
|
page_number = 1
|
||||||
# node_items = await XmppXep0060.get_node_items(xmpp_instance, jid_bare, node_name, item_ids=item_ids_10)
|
else:
|
||||||
# number_of_pages = int(len(item_ids) / 10)
|
ix = 0
|
||||||
# if number_of_pages < len(item_ids) / 10: number_of_pages += 1
|
page_number = 1
|
||||||
|
item_ids_10 = item_ids[ix:][:10]
|
||||||
# if not node_items:
|
number_of_pages = int(len(item_ids) / 10)
|
||||||
# action = 'Warning'
|
if number_of_pages < len(item_ids) / 10: number_of_pages += 1
|
||||||
# node_title = jid_info['condition']
|
node_items = await XmppXep0060.get_node_items(
|
||||||
# node_note = jid_info['text']
|
xmpp_instance, jid_bare, node_name, item_ids=item_ids_10)
|
||||||
# services = services_sorted = None
|
if not node_items:
|
||||||
# elif isinstance(node_items, IqTimeout):
|
action = 'Warning'
|
||||||
# action = 'Warning'
|
node_title = jid_info['condition']
|
||||||
# node_title = 'Timeout'
|
node_note = jid_info['text']
|
||||||
# node_note = 'Timeout error'
|
services = services_sorted = None
|
||||||
# services = services_sorted = None
|
elif isinstance(node_items, IqTimeout):
|
||||||
# elif isinstance(node_items, IqError):
|
action = 'Warning'
|
||||||
# action = 'Warning'
|
node_title = 'Timeout'
|
||||||
# breakpoint()
|
node_note = 'Timeout error'
|
||||||
# node_title = node_items['condition']
|
services = services_sorted = None
|
||||||
# node_note = node_items['text']
|
elif isinstance(node_items, IqError):
|
||||||
# services = services_sorted = None
|
action = 'Warning'
|
||||||
# else:
|
breakpoint()
|
||||||
# if 'items' in node_item_ids['disco_items']:
|
node_title = node_items['condition']
|
||||||
# for item_id in node_item_ids['disco_items']['items']:
|
node_note = node_items['text']
|
||||||
# item_ids.append(item_id[2])
|
services = services_sorted = None
|
||||||
# # NOTE Consider to skip the reversal of order, because, then, items can be found at the same page.
|
else:
|
||||||
# item_ids.reverse()
|
|
||||||
# nodes[node_name] = item_ids
|
|
||||||
#title = title or node_name
|
#title = title or node_name
|
||||||
# if not node_title: node_title = node_name
|
if not node_title: node_title = node_name
|
||||||
# node_note = jid_bare
|
node_note = jid_bare
|
||||||
# for item in node_items['pubsub']['items']:
|
for item in node_items['pubsub']['items']:
|
||||||
# item_payload = item['payload']
|
item_payload = item['payload']
|
||||||
# entry = Syndication.extract_items(item_payload)
|
entry = Syndication.extract_items(item_payload)
|
||||||
# if entry: entry['id'] = item['id']
|
if entry: entry['id'] = item['id']
|
||||||
# entries.append(entry)
|
entries.append(entry)
|
||||||
# #if len(entries) > 10: break
|
#if len(entries) > 10: break
|
||||||
# if entries: entries.reverse()
|
if entries: entries.reverse()
|
||||||
|
|
||||||
|
xmpp_instance.disconnect()
|
||||||
|
|
||||||
# Query URI links
|
# Query URI links
|
||||||
action, instance, link_href, links, node_name, view_href, xmpp_uri = XmppUtilities.set_query_uri_link(
|
action, instance, link_href, links, node_name, view_href, xmpp_uri = XmppUtilities.set_query_uri_link(
|
||||||
jid_bare, jid_info, jid_kind, node_name, item_id)
|
jid_bare, jid_info, jid_kind, node_name, item_id)
|
||||||
|
|
||||||
# Graphic files
|
# Graphic files
|
||||||
filename, filepath, filetype, selection = FileUtilities.handle_photo(jid_bare, jid_detail)
|
filename, filepath, filetype, selection = FileUtilities.handle_photo(jid_bare, jid_vcard)
|
||||||
|
|
||||||
#except Exception as e:
|
#except Exception as e:
|
||||||
else:
|
else:
|
||||||
|
@ -479,7 +495,7 @@ class HttpInstance:
|
||||||
|
|
||||||
#try:
|
#try:
|
||||||
if True:
|
if True:
|
||||||
action = count = exception = instance = jid_detail = \
|
action = count = exception = instance = jid_vcard = \
|
||||||
jid_info = link_href = message = note = selection = title = \
|
jid_info = link_href = message = note = selection = title = \
|
||||||
view_href = xmpp_uri = None
|
view_href = xmpp_uri = None
|
||||||
#node_name = 'urn:xmpp:microblog:0'
|
#node_name = 'urn:xmpp:microblog:0'
|
||||||
|
@ -487,37 +503,45 @@ class HttpInstance:
|
||||||
filename = 'details/{}.toml'.format(jid_bare)
|
filename = 'details/{}.toml'.format(jid_bare)
|
||||||
if os.path.exists(filename) and os.path.getsize(filename) > 0:
|
if os.path.exists(filename) and os.path.getsize(filename) > 0:
|
||||||
jid_details = Data.open_file_toml(filename)
|
jid_details = Data.open_file_toml(filename)
|
||||||
|
else:
|
||||||
|
jid_details = await FileUtilities.cache_jid_data(
|
||||||
|
jabber_id, password, jid_bare, node_name, alias=alias)
|
||||||
|
|
||||||
|
# Set node name to 'urn:xmpp:microblog:0'
|
||||||
|
jid_kind = jid_details['kind']
|
||||||
|
if jid_kind not in ('conference', 'mix', 'muc') and '@' in jid_bare and not node_name:
|
||||||
|
node_name = 'urn:xmpp:microblog:0'
|
||||||
|
|
||||||
action = jid_details['action']
|
action = jid_details['action']
|
||||||
count = jid_details['count']
|
nodes = jid_details['nodes']
|
||||||
|
count = nodes[node_name]['count'] if node_name else jid_details['count']
|
||||||
instance = jid_details['instance']
|
instance = jid_details['instance']
|
||||||
|
items = jid_details['items']
|
||||||
jid_info = {
|
jid_info = {
|
||||||
'error' : jid_details['error'],
|
'error' : jid_details['error'],
|
||||||
'text' : jid_details['error_text'],
|
'text' : jid_details['error_text'],
|
||||||
'condition' : jid_details['error_condition']}
|
'condition' : jid_details['error_condition']}
|
||||||
jid_kind = jid_details['kind']
|
jid_vcard = {
|
||||||
|
'name' : jid_details['name'],
|
||||||
|
'note' : jid_details['note'],
|
||||||
|
'type' : jid_details['image_type']}
|
||||||
link_href = jid_details['link_href']
|
link_href = jid_details['link_href']
|
||||||
messages = jid_details['messages']
|
messages = jid_details['messages']
|
||||||
nodes = jid_details['nodes']
|
|
||||||
note = jid_details['note']
|
note = jid_details['note']
|
||||||
title = jid_details['name']
|
title = jid_details['name']
|
||||||
xmpp_uri = jid_details['uri']
|
xmpp_uri = jid_details['uri']
|
||||||
view_href = jid_details['view_href']
|
view_href = jid_details['view_href']
|
||||||
else:
|
|
||||||
jid_data = await FileUtilities.cache_jid_data(jabber_id, password, jid_bare, node_name, alias=alias)
|
if node_name not in nodes:
|
||||||
count = jid_data['count']
|
nodes[node_name] = await XmppUtilities.get_item_ids_of_node(
|
||||||
jid_detail = jid_data['jid_detail']
|
jabber_id, password, jid_bare, node_name, nodes)
|
||||||
jid_info = jid_data['jid_info']
|
|
||||||
jid_kind = jid_data['jid_kind']
|
|
||||||
jid_details = jid_data['jid_details']
|
|
||||||
note = jid_data['note']
|
|
||||||
title = jid_data['title']
|
|
||||||
|
|
||||||
# Query URI links
|
# Query URI links
|
||||||
action, instance, link_href, links, node_name, view_href, xmpp_uri = XmppUtilities.set_query_uri_link(
|
action, instance, link_href, links, node_name, view_href, xmpp_uri = XmppUtilities.set_query_uri_link(
|
||||||
jid_bare, jid_info, jid_kind, node_name)
|
jid_bare, jid_info, jid_kind, node_name)
|
||||||
|
|
||||||
# Graphic files
|
# Graphic files
|
||||||
filename, filepath, filetype, selection = FileUtilities.handle_photo(jid_bare, jid_detail)
|
filename, filepath, filetype, selection = FileUtilities.handle_photo(jid_bare, jid_vcard)
|
||||||
|
|
||||||
#except Exception as e:
|
#except Exception as e:
|
||||||
else:
|
else:
|
||||||
|
@ -526,7 +550,7 @@ class HttpInstance:
|
||||||
action = 'Error'
|
action = 'Error'
|
||||||
title = 'Slixmpp error'
|
title = 'Slixmpp error'
|
||||||
xmpp_uri = jid
|
xmpp_uri = jid
|
||||||
count = filename = jid_bare = jid_detail = jid_kind = links = \
|
count = filename = jid_bare = jid_vcard = jid_kind = links = \
|
||||||
message = selection = url = None
|
message = selection = url = None
|
||||||
|
|
||||||
template_file = 'jid.xhtml'
|
template_file = 'jid.xhtml'
|
||||||
|
@ -578,7 +602,7 @@ class HttpInstance:
|
||||||
async def main_get(request: Request):
|
async def main_get(request: Request):
|
||||||
jabber_id = request.query_params.get('jid', '')
|
jabber_id = request.query_params.get('jid', '')
|
||||||
if jabber_id:
|
if jabber_id:
|
||||||
response = RedirectResponse(url='/' + jabber_id)
|
response = RedirectResponse(url='/j/' + jabber_id)
|
||||||
else:
|
else:
|
||||||
template_file = 'main.xhtml'
|
template_file = 'main.xhtml'
|
||||||
template_dict = {
|
template_dict = {
|
||||||
|
@ -605,7 +629,7 @@ class FileUtilities:
|
||||||
async def cache_jid_data(jabber_id, password, jid_bare, node_name=None, item_id=None, alias=None):
|
async def cache_jid_data(jabber_id, password, jid_bare, node_name=None, item_id=None, alias=None):
|
||||||
|
|
||||||
count = title = ''
|
count = title = ''
|
||||||
jid_detail = {
|
jid_vcard = {
|
||||||
'name' : '',
|
'name' : '',
|
||||||
'note' : '',
|
'note' : '',
|
||||||
'type' : '',
|
'type' : '',
|
||||||
|
@ -642,7 +666,7 @@ class FileUtilities:
|
||||||
conference_title = identity[3]
|
conference_title = identity[3]
|
||||||
break
|
break
|
||||||
vcard_temp = vcard_data['iq']['vcard_temp']
|
vcard_temp = vcard_data['iq']['vcard_temp']
|
||||||
jid_detail = {
|
jid_vcard = {
|
||||||
'name' : vcard_temp['FN'] or conference_title or '',
|
'name' : vcard_temp['FN'] or conference_title or '',
|
||||||
'note' : vcard_temp['notes'] or node_id or '',
|
'note' : vcard_temp['notes'] or node_id or '',
|
||||||
'type' : vcard_temp['PHOTO']['TYPE'] or '',
|
'type' : vcard_temp['PHOTO']['TYPE'] or '',
|
||||||
|
@ -654,24 +678,27 @@ class FileUtilities:
|
||||||
iq = jid_items['iq']
|
iq = jid_items['iq']
|
||||||
iq_disco_items = iq['disco_items']
|
iq_disco_items = iq['disco_items']
|
||||||
iq_disco_items_items = iq_disco_items['items']
|
iq_disco_items_items = iq_disco_items['items']
|
||||||
iq_disco_items_set = {''}
|
#iq_disco_items_set = {''}
|
||||||
#iq_disco_items_list = []
|
iq_disco_items_list = []
|
||||||
iq_disco_items_items_list = []
|
iq_disco_items_items_list = []
|
||||||
for item in iq_disco_items_items:
|
for item in iq_disco_items_items:
|
||||||
if jid_kind == 'muc':
|
if jid_kind == 'muc':
|
||||||
iq_disco_items_set.update([item[2]])
|
#iq_disco_items_set.update([item[2]])
|
||||||
# iq_disco_items_list.append(item[1])
|
iq_disco_items_list.append(item[2])
|
||||||
else:
|
else:
|
||||||
iq_disco_items_set.update([item[1]])
|
#iq_disco_items_set.update([item[1]])
|
||||||
|
iq_disco_items_list.append(item[1])
|
||||||
iq_disco_items_items_list.append(
|
iq_disco_items_items_list.append(
|
||||||
[item[0] or '', item[1] or '', item[2] or ''])
|
[item[0] or '', item[1] or '', item[2] or ''])
|
||||||
count = len(iq_disco_items_set)
|
#count = len(iq_disco_items_set)
|
||||||
|
count = len(iq_disco_items_list)
|
||||||
|
|
||||||
# Title
|
# Title
|
||||||
print('Title')
|
print('Title')
|
||||||
if jid_kind not in ('conference', 'mix', 'muc') and '@' in jid_bare:
|
if jid_kind not in ('conference', 'mix', 'muc') and '@' in jid_bare:
|
||||||
|
# NOTE Variables node_name and node_title do not appear to be utilized.
|
||||||
node_name = 'urn:xmpp:microblog:0'
|
node_name = 'urn:xmpp:microblog:0'
|
||||||
title = node_title = 'Journal'
|
node_title = 'Journal'
|
||||||
elif jid_kind == 'pubsub':
|
elif jid_kind == 'pubsub':
|
||||||
category = 'unsorted'
|
category = 'unsorted'
|
||||||
for item in iq_disco_items_items:
|
for item in iq_disco_items_items:
|
||||||
|
@ -692,8 +719,8 @@ class FileUtilities:
|
||||||
print(jid_info)
|
print(jid_info)
|
||||||
# String 'undefined' is sourced from JID discuss@conference.conversejs.org
|
# String 'undefined' is sourced from JID discuss@conference.conversejs.org
|
||||||
if not title:
|
if not title:
|
||||||
if jid_detail['name'] and not 'undefined' in jid_detail['name']:
|
if jid_vcard['name'] and not 'undefined' in jid_vcard['name']:
|
||||||
title = jid_detail['name']
|
title = jid_vcard['name']
|
||||||
else:
|
else:
|
||||||
title = jid_bare.split('@')[0]
|
title = jid_bare.split('@')[0]
|
||||||
|
|
||||||
|
@ -746,15 +773,15 @@ class FileUtilities:
|
||||||
# Node items
|
# Node items
|
||||||
print('Node items')
|
print('Node items')
|
||||||
nodes = {}
|
nodes = {}
|
||||||
nodes[node_name] = {}
|
#if node_name and node_name in iq_disco_items_set:
|
||||||
if node_name and node_name in iq_disco_items_set:
|
if node_name and node_name in iq_disco_items_list:
|
||||||
#if node_name and node_name in iq_disco_items_list:
|
|
||||||
action = 'Browse'
|
action = 'Browse'
|
||||||
node_item_ids = await XmppXep0060.get_node_item_ids(xmpp_instance, jid_bare, node_name)
|
node_item_ids = await XmppXep0060.get_node_item_ids(xmpp_instance, jid_bare, node_name)
|
||||||
if isinstance(node_item_ids, stanza.iq.Iq):
|
if isinstance(node_item_ids['iq'], stanza.iq.Iq):
|
||||||
nodes[node_name]['count'] = len(node_item_ids['disco_items']['items'])
|
nodes[node_name] = {}
|
||||||
|
nodes[node_name]['count'] = len(node_item_ids['iq']['disco_items']['items'])
|
||||||
nodes[node_name]['item_ids'] = []
|
nodes[node_name]['item_ids'] = []
|
||||||
for item_id in node_item_ids['disco_items']['items']:
|
for item_id in node_item_ids['iq']['disco_items']['items']:
|
||||||
nodes[node_name]['item_ids'].append(
|
nodes[node_name]['item_ids'].append(
|
||||||
[item_id[0] or '', item_id[1] or '', item_id[2] or ''])
|
[item_id[0] or '', item_id[1] or '', item_id[2] or ''])
|
||||||
|
|
||||||
|
@ -762,13 +789,13 @@ class FileUtilities:
|
||||||
|
|
||||||
# Notes
|
# Notes
|
||||||
print('Notes')
|
print('Notes')
|
||||||
jid_detail_note = jid_detail['note']
|
jid_vcard_note = jid_vcard['note']
|
||||||
if isinstance(jid_detail_note, list) and len(jid_detail_note):
|
if isinstance(jid_vcard_note, list) and len(jid_vcard_note):
|
||||||
note = jid_detail_note[0]['NOTE']
|
note = jid_vcard_note[0]['NOTE']
|
||||||
else:
|
else:
|
||||||
note = jid_detail_note
|
note = jid_vcard_note
|
||||||
#if not note and jid_detail['name'] and not 'undefined' in jid_detail['name'] and title != jid_detail['name']:
|
#if not note and jid_vcard['name'] and not 'undefined' in jid_vcard['name'] and title != jid_vcard['name']:
|
||||||
# note = jid_detail['name']
|
# note = jid_vcard['name']
|
||||||
|
|
||||||
jid_details = {
|
jid_details = {
|
||||||
'action' : action or '',
|
'action' : action or '',
|
||||||
|
@ -776,10 +803,11 @@ class FileUtilities:
|
||||||
'error' : jid_info['error'],
|
'error' : jid_info['error'],
|
||||||
'error_text' : jid_info['text'] or '',
|
'error_text' : jid_info['text'] or '',
|
||||||
'error_condition' : jid_info['condition'] or '',
|
'error_condition' : jid_info['condition'] or '',
|
||||||
'items' : iq_disco_items_items_list,
|
'image_type' : jid_vcard['type'],
|
||||||
'link_href' : link_href,
|
|
||||||
'instance' : instance or '',
|
'instance' : instance or '',
|
||||||
|
'items' : iq_disco_items_items_list,
|
||||||
'kind' : jid_kind or '',
|
'kind' : jid_kind or '',
|
||||||
|
'link_href' : link_href,
|
||||||
'messages' : messages or '',
|
'messages' : messages or '',
|
||||||
'name' : title,
|
'name' : title,
|
||||||
'nodes' : nodes,
|
'nodes' : nodes,
|
||||||
|
@ -792,19 +820,9 @@ class FileUtilities:
|
||||||
filename = 'details/{}.toml'.format(jid_bare)
|
filename = 'details/{}.toml'.format(jid_bare)
|
||||||
Data.save_to_toml(filename, jid_details)
|
Data.save_to_toml(filename, jid_details)
|
||||||
|
|
||||||
result = {
|
return jid_details
|
||||||
'count' : nodes[node_name]['count'] if node_name else count or '',
|
|
||||||
'jid_detail' : jid_detail,
|
|
||||||
'jid_info' : jid_info,
|
|
||||||
'jid_items' : jid_items,
|
|
||||||
'jid_kind' : jid_kind,
|
|
||||||
'jid_details' : jid_details,
|
|
||||||
'note' : note,
|
|
||||||
'title' : title}
|
|
||||||
|
|
||||||
return result
|
def handle_photo(jid_bare, jid_vcard):
|
||||||
|
|
||||||
def handle_photo(jid_bare, jid_detail):
|
|
||||||
filetype = selection = None
|
filetype = selection = None
|
||||||
filecirca = 'photo/{}.*'.format(jid_bare)
|
filecirca = 'photo/{}.*'.format(jid_bare)
|
||||||
filepath = glob.glob(filecirca)
|
filepath = glob.glob(filecirca)
|
||||||
|
@ -812,10 +830,10 @@ class FileUtilities:
|
||||||
filepath = filepath[0]
|
filepath = filepath[0]
|
||||||
filetype = filepath.split('.').pop()
|
filetype = filepath.split('.').pop()
|
||||||
filename = '{}.{}'.format(jid_bare, filetype)
|
filename = '{}.{}'.format(jid_bare, filetype)
|
||||||
elif jid_detail:
|
elif jid_vcard:
|
||||||
mimetype = filename = filepath = None
|
mimetype = filename = filepath = None
|
||||||
if jid_detail['type']:
|
if jid_vcard['type']:
|
||||||
mimetype = jid_detail['type']
|
mimetype = jid_vcard['type']
|
||||||
if mimetype:
|
if mimetype:
|
||||||
filetype = mimetype.split('/')[1]
|
filetype = mimetype.split('/')[1]
|
||||||
if filetype == 'svg+xml': filetype = 'svg'
|
if filetype == 'svg+xml': filetype = 'svg'
|
||||||
|
@ -825,7 +843,7 @@ class FileUtilities:
|
||||||
|
|
||||||
# Write the decoded bytes to a file
|
# Write the decoded bytes to a file
|
||||||
with open(filepath, 'wb') as file:
|
with open(filepath, 'wb') as file:
|
||||||
file.write(jid_detail['bin'])
|
file.write(jid_vcard['bin'])
|
||||||
|
|
||||||
if not filepath or not os.path.exists(filepath) or os.path.getsize(filepath) == 0:
|
if not filepath or not os.path.exists(filepath) or os.path.getsize(filepath) == 0:
|
||||||
filename = 'default.svg'
|
filename = 'default.svg'
|
||||||
|
@ -1021,16 +1039,12 @@ class Syndication:
|
||||||
|
|
||||||
class XmppUtilities:
|
class XmppUtilities:
|
||||||
|
|
||||||
async def count_jid_items(xmpp_instance, jid_bare, node_name, jid_kind):
|
async def get_item_ids_of_node(jabber_id, password, jid_bare, node_name, nodes):
|
||||||
if jid_kind in ('mix', 'muc', 'conference', 'server'):
|
xmpp_instance = XmppInstance(jabber_id, password, jid_bare)
|
||||||
jid_items = await XmppXep0030.get_jid_items(xmpp_instance, jid_bare)
|
xmpp_instance.connect()
|
||||||
if isinstance(jid_items['iq'], stanza.iq.Iq):
|
|
||||||
count = len(jid_items['iq']['disco_items']['items'])
|
|
||||||
elif jid_kind in ('account', 'pubsub'):
|
|
||||||
node_item_ids = await XmppXep0060.get_node_item_ids(xmpp_instance, jid_bare, node_name)
|
node_item_ids = await XmppXep0060.get_node_item_ids(xmpp_instance, jid_bare, node_name)
|
||||||
if isinstance(node_item_ids, stanza.iq.Iq):
|
xmpp_instance.disconnect()
|
||||||
count = len(node_item_ids['disco_items']['items'])
|
return node_item_ids
|
||||||
return count
|
|
||||||
|
|
||||||
def set_query_uri_link(jid_bare, jid_info, jid_kind, node_name=None, item_id=None):
|
def set_query_uri_link(jid_bare, jid_info, jid_kind, node_name=None, item_id=None):
|
||||||
links = []
|
links = []
|
||||||
|
@ -1322,21 +1336,28 @@ class XmppXep0060:
|
||||||
|
|
||||||
async def get_node_item_ids(self, jid_bare, node_name):
|
async def get_node_item_ids(self, jid_bare, node_name):
|
||||||
try:
|
try:
|
||||||
|
error = False
|
||||||
|
condition = text = None
|
||||||
iq = await self['xep_0030'].get_items(
|
iq = await self['xep_0030'].get_items(
|
||||||
jid_bare, node_name)
|
jid_bare, node_name)
|
||||||
# Broken. See https://codeberg.org/poezio/slixmpp/issues/3548
|
# Broken. See https://codeberg.org/poezio/slixmpp/issues/3548
|
||||||
#iq = await self['xep_0060'].get_item_ids(
|
#iq = await self['xep_0060'].get_item_ids(
|
||||||
# jid_bare, node_name, timeout=5)
|
# jid_bare, node_name, timeout=5)
|
||||||
result = iq
|
except (IqError, IqTimeout) as e:
|
||||||
except IqError as e:
|
error = True
|
||||||
if e.iq['error']['text'] == 'Node not found':
|
condition = e.iq['error']['condition']
|
||||||
result = 'Node not found'
|
text = e.iq['error']['text']
|
||||||
elif e.iq['error']['condition'] == 'item-not-found':
|
if not text:
|
||||||
result = 'Item not found'
|
if condition:
|
||||||
|
text = 'Could not retrieve node items'
|
||||||
else:
|
else:
|
||||||
result = None
|
text = 'Unknown Error'
|
||||||
except IqTimeout as e:
|
iq = None
|
||||||
result = e
|
result = {
|
||||||
|
'error' : error,
|
||||||
|
'condition' : condition,
|
||||||
|
'text' : text,
|
||||||
|
'iq' : iq}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
class XmppXep0369:
|
class XmppXep0369:
|
||||||
|
|
Loading…
Reference in a new issue