Mercurial > xmpp-account-manager
diff 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 |
line wrap: on
line diff
--- a/util.js +++ b/util.js @@ -1,3 +1,5 @@ +'use strict'; + const NS = { xrd: 'http://docs.oasis-open.org/ns/xri/xrd-1.0', roster: 'jabber:iq:roster', @@ -69,6 +71,35 @@ function parseErrorIq(iq) { return condition.localName + ': ' + text.textContent; } +function retrieveConfiguration(connection) +{ + return new Promise((resolve, reject) => { + const iq = $iq({type: 'get'}) + .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub#owner'}) + .c('configure', {node: 'http://jabber.org/protocol/nick'}); + connection.sendIQ(iq, onNodeConfigure.bind(null, resolve, reject), reject); + }); +} + +function onNodeConfigure(resolve, reject, result_iq) +{ + const fields = parseXPath(result_iq, './pubsub_owner:pubsub/pubsub_owner:configure/dataforms:x/dataforms:field', XPathResult.UNORDERED_NODE_ITERATOR_TYPE); + if (fields === null) + return reject('no fields'); + let access_model = null; + while (true) { + const field = fields.iterateNext(); + if (field === null) + break; + const var_ = field.getAttributeNS(null, 'var'); + if (var_ === 'pubsub#access_model') { + const value = parseXPath(field, './dataforms:value'); + access_model = value.textContent; + } + } + return resolve(access_model); +} + function displaySpinner(spinner) { if ('timeoutid' in spinner.dataset) clearTimeout(spinner.dataset.timeoutid);