Mercurial > xmpp-account-manager
comparison nickname.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 | b76146a09e07 |
children | 2f45bee88b47 |
comparison
equal
deleted
inserted
replaced
47:b76146a09e07 | 48:021185105e2f |
---|---|
9 const iq = $iq({type: 'get'}) | 9 const iq = $iq({type: 'get'}) |
10 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) | 10 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) |
11 .c('items', {node: 'http://jabber.org/protocol/nick'}); | 11 .c('items', {node: 'http://jabber.org/protocol/nick'}); |
12 connection.sendIQ(iq, onNickname, onNicknameRetrievalError); | 12 connection.sendIQ(iq, onNickname, onNicknameRetrievalError); |
13 displaySpinner(spinner_img); | 13 displaySpinner(spinner_img); |
14 retrieveConfiguration(); | 14 getNicknameAccessModel(); |
15 displaySpinner(access_spinner_img); | 15 displaySpinner(access_spinner_img); |
16 | 16 |
17 function retrieveConfiguration() | 17 function getNicknameAccessModel() |
18 { | 18 { |
19 const iq = $iq({type: 'get'}) | 19 retrieveConfiguration(connection).then((access_model) => { |
20 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub#owner'}) | 20 console.log('yay', access_model); |
21 .c('configure', {node: 'http://jabber.org/protocol/nick'}); | 21 if (access_model !== null) { |
22 connection.sendIQ(iq, onConfigure, onConfigureError); | 22 if (access_model === 'open') |
23 } | 23 nick_access.value = 'open'; |
24 | 24 else if (access_model === 'presence') |
25 function onConfigure(result_iq) | 25 nick_access.value = 'presence'; |
26 { | 26 else |
27 const fields = parseXPath(result_iq, './pubsub_owner:pubsub/pubsub_owner:configure/dataforms:x/dataforms:field', XPathResult.UNORDERED_NODE_ITERATOR_TYPE); | 27 console.log('Unsupported nickname access model: ' + access_model); |
28 if (fields === null) { | 28 nick_access.disabled = false; |
29 console.log('Failed to retrieve nickname configuration.'); | |
30 hideSpinner(spinner_img); | |
31 return; | |
32 } | |
33 let access_model = null; | |
34 while (true) { | |
35 const field = fields.iterateNext(); | |
36 if (field === null) | |
37 break; | |
38 const var_ = field.getAttributeNS(null, 'var'); | |
39 if (var_ === 'pubsub#access_model') { | |
40 const value = parseXPath(field, './dataforms:value'); | |
41 access_model = value.textContent; | |
42 } | 29 } |
43 } | 30 hideSpinner(access_spinner_img); |
44 if (access_model !== null) { | 31 }, (reason) => { |
45 if (access_model === 'open') | 32 console.log('Failed to retrieve nickname configuration: ' + reason); |
46 nick_access.value = 'open'; | 33 hideSpinner(access_spinner_img); |
47 else if (access_model === 'presence') | 34 }); |
48 nick_access.value = 'presence'; | |
49 else | |
50 console.log('Unsupported nickname access model: ' + access_model); | |
51 nick_access.disabled = false; | |
52 } | |
53 hideSpinner(access_spinner_img); | |
54 } | |
55 | |
56 function onConfigureError(iq) | |
57 { | |
58 console.log('Failed to retrieve nickname configuration: ' + parseErrorIq(iq)); | |
59 nick_access.disabled = true; | |
60 hideSpinner(access_spinner_img); | |
61 } | 35 } |
62 | 36 |
63 function onNickname(result_iq) | 37 function onNickname(result_iq) |
64 { | 38 { |
65 const item = parseXPath(result_iq, './pubsub:pubsub/pubsub:items/pubsub:item'); | 39 const item = parseXPath(result_iq, './pubsub:pubsub/pubsub:items/pubsub:item'); |
106 function onNicknameChanged(action, result_iq) | 80 function onNicknameChanged(action, result_iq) |
107 { | 81 { |
108 console.log('Nickname successfully ' + action + '.'); | 82 console.log('Nickname successfully ' + action + '.'); |
109 nick_access.disabled = true; | 83 nick_access.disabled = true; |
110 if (action === 'changed') | 84 if (action === 'changed') |
111 retrieveConfiguration(); | 85 getNicknameAccessModel(); |
112 spinnerOk(spinner_img); | 86 spinnerOk(spinner_img); |
113 } | 87 } |
114 | 88 |
115 function onNicknameChangeError(iq) | 89 function onNicknameChangeError(iq) |
116 { | 90 { |