comparison util.js @ 48:021185105e2f

Move the node configuration retrieval to a util promise.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 23 May 2020 20:37:20 +0200
parents b15e1581c3d4
children 2f45bee88b47
comparison
equal deleted inserted replaced
47:b76146a09e07 48:021185105e2f
1 'use strict';
2
1 const NS = { 3 const NS = {
2 xrd: 'http://docs.oasis-open.org/ns/xri/xrd-1.0', 4 xrd: 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
3 roster: 'jabber:iq:roster', 5 roster: 'jabber:iq:roster',
4 disco_items: 'http://jabber.org/protocol/disco#items', 6 disco_items: 'http://jabber.org/protocol/disco#items',
5 disco_info: 'http://jabber.org/protocol/disco#info', 7 disco_info: 'http://jabber.org/protocol/disco#info',
67 if (text.namespaceURI !== 'urn:ietf:params:xml:ns:xmpp-stanzas' || text.localName !== 'text') 69 if (text.namespaceURI !== 'urn:ietf:params:xml:ns:xmpp-stanzas' || text.localName !== 'text')
68 return null; 70 return null;
69 return condition.localName + ': ' + text.textContent; 71 return condition.localName + ': ' + text.textContent;
70 } 72 }
71 73
74 function retrieveConfiguration(connection)
75 {
76 return new Promise((resolve, reject) => {
77 const iq = $iq({type: 'get'})
78 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub#owner'})
79 .c('configure', {node: 'http://jabber.org/protocol/nick'});
80 connection.sendIQ(iq, onNodeConfigure.bind(null, resolve, reject), reject);
81 });
82 }
83
84 function onNodeConfigure(resolve, reject, result_iq)
85 {
86 const fields = parseXPath(result_iq, './pubsub_owner:pubsub/pubsub_owner:configure/dataforms:x/dataforms:field', XPathResult.UNORDERED_NODE_ITERATOR_TYPE);
87 if (fields === null)
88 return reject('no fields');
89 let access_model = null;
90 while (true) {
91 const field = fields.iterateNext();
92 if (field === null)
93 break;
94 const var_ = field.getAttributeNS(null, 'var');
95 if (var_ === 'pubsub#access_model') {
96 const value = parseXPath(field, './dataforms:value');
97 access_model = value.textContent;
98 }
99 }
100 return resolve(access_model);
101 }
102
72 function displaySpinner(spinner) { 103 function displaySpinner(spinner) {
73 if ('timeoutid' in spinner.dataset) 104 if ('timeoutid' in spinner.dataset)
74 clearTimeout(spinner.dataset.timeoutid); 105 clearTimeout(spinner.dataset.timeoutid);
75 spinner.src = 'spinner.svg'; 106 spinner.src = 'spinner.svg';
76 spinner.title = ''; 107 spinner.title = '';