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;
|
||||||
}
|
}
|
||||||
|
|
449
fasi.py
449
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,54 +102,54 @@ 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)
|
||||||
action = jid_details['action']
|
|
||||||
count = jid_details['count']
|
|
||||||
instance = jid_details['instance']
|
|
||||||
jid_info = {
|
|
||||||
'error' : jid_details['error'],
|
|
||||||
'text' : jid_details['error_text'],
|
|
||||||
'condition' : jid_details['error_condition']}
|
|
||||||
jid_kind = jid_details['kind']
|
|
||||||
link_href = jid_details['link_href']
|
|
||||||
messages = jid_details['messages']
|
|
||||||
nodes = jid_details['nodes']
|
|
||||||
note = jid_details['note']
|
|
||||||
title = jid_details['name']
|
|
||||||
xmpp_uri = jid_details['uri']
|
|
||||||
view_href = jid_details['view_href']
|
|
||||||
else:
|
else:
|
||||||
jid_data = await FileUtilities.cache_jid_data(jabber_id, password, jid_bare, node_name, alias=alias)
|
jid_details = await FileUtilities.cache_jid_data(
|
||||||
count = jid_data['count']
|
jabber_id, password, jid_bare, node_name, alias=alias)
|
||||||
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
|
action = jid_details['action']
|
||||||
# NOTE TODO
|
count = jid_details['count']
|
||||||
page_number = request.query_params.get('page', '')
|
instance = jid_details['instance']
|
||||||
if page_number:
|
items = jid_details['items']
|
||||||
try:
|
jid_info = {
|
||||||
page_number = int(page_number)
|
'error' : jid_details['error'],
|
||||||
ix = (page_number -1) * 10
|
'text' : jid_details['error_text'],
|
||||||
except:
|
'condition' : jid_details['error_condition']}
|
||||||
ix = 0
|
jid_kind = jid_details['kind']
|
||||||
page_number = 1
|
jid_vcard = {
|
||||||
else:
|
'name' : jid_details['name'],
|
||||||
|
'note' : jid_details['note'],
|
||||||
|
'type' : jid_details['image_type']}
|
||||||
|
link_href = jid_details['link_href']
|
||||||
|
messages = jid_details['messages']
|
||||||
|
nodes = jid_details['nodes']
|
||||||
|
note = jid_details['note']
|
||||||
|
title = jid_details['name']
|
||||||
|
xmpp_uri = jid_details['uri']
|
||||||
|
view_href = jid_details['view_href']
|
||||||
|
|
||||||
|
# Group chat messages
|
||||||
|
# NOTE TODO
|
||||||
|
page_number = request.query_params.get('page', '')
|
||||||
|
if page_number:
|
||||||
|
try:
|
||||||
|
page_number = int(page_number)
|
||||||
|
ix = (page_number -1) * 10
|
||||||
|
except:
|
||||||
ix = 0
|
ix = 0
|
||||||
page_number = 1
|
page_number = 1
|
||||||
messages_10 = messages[ix:][:10]
|
else:
|
||||||
number_of_pages = int(len(messages) / 10)
|
ix = 0
|
||||||
if number_of_pages < len(messages) / 10: number_of_pages += 1
|
page_number = 1
|
||||||
|
messages_10 = messages[ix:][:10]
|
||||||
|
number_of_pages = int(len(messages) / 10)
|
||||||
|
if number_of_pages < len(messages) / 10: number_of_pages += 1
|
||||||
|
|
||||||
# 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:
|
||||||
|
@ -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,109 +203,123 @@ 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)
|
||||||
action = jid_details['action']
|
|
||||||
count = jid_details['count']
|
|
||||||
instance = jid_details['instance']
|
|
||||||
jid_info = {
|
|
||||||
'error' : jid_details['error'],
|
|
||||||
'text' : jid_details['error_text'],
|
|
||||||
'condition' : jid_details['error_condition']}
|
|
||||||
jid_kind = jid_details['kind']
|
|
||||||
link_href = jid_details['link_href']
|
|
||||||
messages = jid_details['messages']
|
|
||||||
nodes = jid_details['nodes']
|
|
||||||
note = jid_details['note']
|
|
||||||
title = jid_details['name']
|
|
||||||
xmpp_uri = jid_details['uri']
|
|
||||||
view_href = jid_details['view_href']
|
|
||||||
if node_name not in nodes:
|
|
||||||
node_item_ids = await XmppXep0060.get_node_item_ids(xmpp_instance, jid_bare, node_name)
|
|
||||||
if isinstance(node_item_ids, stanza.iq.Iq):
|
|
||||||
nodes[node_name] = node_item_ids['disco_items']['items']
|
|
||||||
else:
|
else:
|
||||||
jid_data = await FileUtilities.cache_jid_data(jabber_id, password, jid_bare, node_name, item_id)
|
jid_details = await FileUtilities.cache_jid_data(
|
||||||
count = jid_data['count']
|
jabber_id, password, jid_bare, node_name, item_id)
|
||||||
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']
|
|
||||||
|
|
||||||
# Node items
|
action = jid_details['action']
|
||||||
# NOTE TODO
|
count = jid_details['count']
|
||||||
# page_number = request.query_params.get('page', '')
|
instance = jid_details['instance']
|
||||||
# if page_number:
|
items = jid_details['items']
|
||||||
# try:
|
jid_info = {
|
||||||
# page_number = int(page_number)
|
'error' : jid_details['error'],
|
||||||
# ix = (page_number -1) * 10
|
'text' : jid_details['error_text'],
|
||||||
# except:
|
'condition' : jid_details['error_condition']}
|
||||||
# ix = 0
|
jid_kind = jid_details['kind']
|
||||||
# page_number = 1
|
jid_vcard = {
|
||||||
# else:
|
'name' : jid_details['name'],
|
||||||
# ix = 0
|
'note' : jid_details['note'],
|
||||||
# page_number = 1
|
'type' : jid_details['image_type']}
|
||||||
# item_ids_10 = item_ids[ix:][:10]
|
link_href = jid_details['link_href']
|
||||||
|
messages = jid_details['messages']
|
||||||
|
nodes = jid_details['nodes']
|
||||||
|
note = jid_details['note']
|
||||||
|
title = jid_details['name']
|
||||||
|
xmpp_uri = jid_details['uri']
|
||||||
|
view_href = jid_details['view_href']
|
||||||
|
|
||||||
# if item_id:
|
xmpp_instance = XmppInstance(jabber_id, password, jid_bare)
|
||||||
# previous = True
|
xmpp_instance.connect()
|
||||||
# node_items = await XmppXep0060.get_node_items(xmpp_instance, jid_bare, node_name, item_ids=[item_id])
|
|
||||||
# else:
|
|
||||||
# node_items = await XmppXep0060.get_node_items(xmpp_instance, jid_bare, node_name, item_ids=item_ids_10)
|
|
||||||
# number_of_pages = int(len(item_ids) / 10)
|
|
||||||
# if number_of_pages < len(item_ids) / 10: number_of_pages += 1
|
|
||||||
|
|
||||||
# if not node_items:
|
# Node item IDs
|
||||||
# action = 'Warning'
|
if node_name not in nodes:
|
||||||
# node_title = jid_info['condition']
|
nodes[node_name] = {}
|
||||||
# node_note = jid_info['text']
|
node_item_ids = await XmppXep0060.get_node_item_ids(
|
||||||
# services = services_sorted = None
|
xmpp_instance, jid_bare, node_name)
|
||||||
# elif isinstance(node_items, IqTimeout):
|
#node_item_ids = await XmppUtilities.get_item_ids_of_node(
|
||||||
# action = 'Warning'
|
# jabber_id, password, jid_bare, node_name, nodes)
|
||||||
# node_title = 'Timeout'
|
if isinstance(node_item_ids['iq'], stanza.iq.Iq):
|
||||||
# node_note = 'Timeout error'
|
nodes[node_name]['count'] = len(node_item_ids['iq']['disco_items']['items'])
|
||||||
# services = services_sorted = None
|
nodes[node_name]['item_ids'] = []
|
||||||
# elif isinstance(node_items, IqError):
|
for item in node_item_ids['iq']['disco_items']['items']:
|
||||||
# action = 'Warning'
|
nodes[node_name]['item_ids'].append(
|
||||||
# breakpoint()
|
[item[0] or '', item[1] or '', item[2] or ''])
|
||||||
# node_title = node_items['condition']
|
|
||||||
# node_note = node_items['text']
|
# Node items
|
||||||
# services = services_sorted = None
|
if item_id:
|
||||||
# else:
|
previous = True
|
||||||
# if 'items' in node_item_ids['disco_items']:
|
node_items = await XmppXep0060.get_node_items(
|
||||||
# for item_id in node_item_ids['disco_items']['items']:
|
xmpp_instance, jid_bare, node_name, item_ids=[item_id])
|
||||||
# item_ids.append(item_id[2])
|
else:
|
||||||
# # NOTE Consider to skip the reversal of order, because, then, items can be found at the same page.
|
item_ids = []
|
||||||
# item_ids.reverse()
|
for item in nodes[node_name]['item_ids']:
|
||||||
# nodes[node_name] = item_ids
|
item_ids.append(item[2])
|
||||||
#title = title or node_name
|
# NOTE Consider to neglect the reversal of order, because, then, items can be found at the same page.
|
||||||
# if not node_title: node_title = node_name
|
item_ids.reverse()
|
||||||
# node_note = jid_bare
|
page_number = request.query_params.get('page', '')
|
||||||
# for item in node_items['pubsub']['items']:
|
if page_number:
|
||||||
# item_payload = item['payload']
|
try:
|
||||||
# entry = Syndication.extract_items(item_payload)
|
page_number = int(page_number)
|
||||||
# if entry: entry['id'] = item['id']
|
ix = (page_number -1) * 10
|
||||||
# entries.append(entry)
|
except:
|
||||||
# #if len(entries) > 10: break
|
ix = 0
|
||||||
# if entries: entries.reverse()
|
page_number = 1
|
||||||
|
else:
|
||||||
|
ix = 0
|
||||||
|
page_number = 1
|
||||||
|
item_ids_10 = item_ids[ix:][:10]
|
||||||
|
number_of_pages = int(len(item_ids) / 10)
|
||||||
|
if number_of_pages < len(item_ids) / 10: number_of_pages += 1
|
||||||
|
node_items = await XmppXep0060.get_node_items(
|
||||||
|
xmpp_instance, jid_bare, node_name, item_ids=item_ids_10)
|
||||||
|
if not node_items:
|
||||||
|
action = 'Warning'
|
||||||
|
node_title = jid_info['condition']
|
||||||
|
node_note = jid_info['text']
|
||||||
|
services = services_sorted = None
|
||||||
|
elif isinstance(node_items, IqTimeout):
|
||||||
|
action = 'Warning'
|
||||||
|
node_title = 'Timeout'
|
||||||
|
node_note = 'Timeout error'
|
||||||
|
services = services_sorted = None
|
||||||
|
elif isinstance(node_items, IqError):
|
||||||
|
action = 'Warning'
|
||||||
|
breakpoint()
|
||||||
|
node_title = node_items['condition']
|
||||||
|
node_note = node_items['text']
|
||||||
|
services = services_sorted = None
|
||||||
|
else:
|
||||||
|
#title = title or node_name
|
||||||
|
if not node_title: node_title = node_name
|
||||||
|
node_note = jid_bare
|
||||||
|
for item in node_items['pubsub']['items']:
|
||||||
|
item_payload = item['payload']
|
||||||
|
entry = Syndication.extract_items(item_payload)
|
||||||
|
if entry: entry['id'] = item['id']
|
||||||
|
entries.append(entry)
|
||||||
|
#if len(entries) > 10: break
|
||||||
|
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)
|
||||||
action = jid_details['action']
|
|
||||||
count = jid_details['count']
|
|
||||||
instance = jid_details['instance']
|
|
||||||
jid_info = {
|
|
||||||
'error' : jid_details['error'],
|
|
||||||
'text' : jid_details['error_text'],
|
|
||||||
'condition' : jid_details['error_condition']}
|
|
||||||
jid_kind = jid_details['kind']
|
|
||||||
link_href = jid_details['link_href']
|
|
||||||
messages = jid_details['messages']
|
|
||||||
nodes = jid_details['nodes']
|
|
||||||
note = jid_details['note']
|
|
||||||
title = jid_details['name']
|
|
||||||
xmpp_uri = jid_details['uri']
|
|
||||||
view_href = jid_details['view_href']
|
|
||||||
else:
|
else:
|
||||||
jid_data = await FileUtilities.cache_jid_data(jabber_id, password, jid_bare, node_name, alias=alias)
|
jid_details = await FileUtilities.cache_jid_data(
|
||||||
count = jid_data['count']
|
jabber_id, password, jid_bare, node_name, alias=alias)
|
||||||
jid_detail = jid_data['jid_detail']
|
|
||||||
jid_info = jid_data['jid_info']
|
# Set node name to 'urn:xmpp:microblog:0'
|
||||||
jid_kind = jid_data['jid_kind']
|
jid_kind = jid_details['kind']
|
||||||
jid_details = jid_data['jid_details']
|
if jid_kind not in ('conference', 'mix', 'muc') and '@' in jid_bare and not node_name:
|
||||||
note = jid_data['note']
|
node_name = 'urn:xmpp:microblog:0'
|
||||||
title = jid_data['title']
|
|
||||||
|
action = jid_details['action']
|
||||||
|
nodes = jid_details['nodes']
|
||||||
|
count = nodes[node_name]['count'] if node_name else jid_details['count']
|
||||||
|
instance = jid_details['instance']
|
||||||
|
items = jid_details['items']
|
||||||
|
jid_info = {
|
||||||
|
'error' : jid_details['error'],
|
||||||
|
'text' : jid_details['error_text'],
|
||||||
|
'condition' : jid_details['error_condition']}
|
||||||
|
jid_vcard = {
|
||||||
|
'name' : jid_details['name'],
|
||||||
|
'note' : jid_details['note'],
|
||||||
|
'type' : jid_details['image_type']}
|
||||||
|
link_href = jid_details['link_href']
|
||||||
|
messages = jid_details['messages']
|
||||||
|
note = jid_details['note']
|
||||||
|
title = jid_details['name']
|
||||||
|
xmpp_uri = jid_details['uri']
|
||||||
|
view_href = jid_details['view_href']
|
||||||
|
|
||||||
|
if node_name not in nodes:
|
||||||
|
nodes[node_name] = await XmppUtilities.get_item_ids_of_node(
|
||||||
|
jabber_id, password, jid_bare, node_name, nodes)
|
||||||
|
|
||||||
# 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):
|
node_item_ids = await XmppXep0060.get_node_item_ids(xmpp_instance, jid_bare, node_name)
|
||||||
count = len(jid_items['iq']['disco_items']['items'])
|
xmpp_instance.disconnect()
|
||||||
elif jid_kind in ('account', 'pubsub'):
|
return node_item_ids
|
||||||
node_item_ids = await XmppXep0060.get_node_item_ids(xmpp_instance, jid_bare, node_name)
|
|
||||||
if isinstance(node_item_ids, stanza.iq.Iq):
|
|
||||||
count = len(node_item_ids['disco_items']['items'])
|
|
||||||
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:
|
||||||
else:
|
text = 'Could not retrieve node items'
|
||||||
result = None
|
else:
|
||||||
except IqTimeout as e:
|
text = 'Unknown Error'
|
||||||
result = e
|
iq = None
|
||||||
|
result = {
|
||||||
|
'error' : error,
|
||||||
|
'condition' : condition,
|
||||||
|
'text' : text,
|
||||||
|
'iq' : iq}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
class XmppXep0369:
|
class XmppXep0369:
|
||||||
|
|
Loading…
Reference in a new issue