Mercurial > xmpp-account-manager
comparison vcard.js @ 55:6a7a99f5a0ca
Add pubsub#access_model retrieval for the vCard4 node.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 23 May 2020 21:59:17 +0200 |
parents | 45bd945c5722 |
children | 6d861d881b96 |
comparison
equal
deleted
inserted
replaced
54:9ada1963558c | 55:6a7a99f5a0ca |
---|---|
14 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) | 14 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) |
15 .c('items', {node: 'urn:xmpp:vcard4'}) | 15 .c('items', {node: 'urn:xmpp:vcard4'}) |
16 .c('item', {id: 'current'}); | 16 .c('item', {id: 'current'}); |
17 connection.sendIQ(iq, onVCard4, onVCard4RetrievalError); | 17 connection.sendIQ(iq, onVCard4, onVCard4RetrievalError); |
18 displaySpinner(spinner_img); | 18 displaySpinner(spinner_img); |
19 getAccessModel(); | |
20 | |
21 function getAccessModel() | |
22 { | |
23 vcard_access.disabled = true; | |
24 displaySpinner(access_spinner_img); | |
25 retrieveConfiguration(connection, 'urn:xmpp:vcard4').then((access_model) => { | |
26 if (access_model !== null) { | |
27 if (access_model === 'open') | |
28 vcard_access.value = 'open'; | |
29 else if (access_model === 'presence') | |
30 vcard_access.value = 'presence'; | |
31 else | |
32 console.log('Unsupported vCard4 access model: ' + access_model); | |
33 vcard_access.disabled = false; | |
34 } | |
35 hideSpinner(access_spinner_img); | |
36 }, (reason) => { | |
37 console.log('Failed to retrieve vCard4 configuration:', reason); | |
38 hideSpinner(access_spinner_img); | |
39 }); | |
40 } | |
19 | 41 |
20 function onVCard4(result_iq) | 42 function onVCard4(result_iq) |
21 { | 43 { |
22 const item = parseXPath(result_iq, './pubsub:pubsub/pubsub:items/pubsub:item'); | 44 const item = parseXPath(result_iq, './pubsub:pubsub/pubsub:items/pubsub:item'); |
23 if (item === null) | 45 if (item === null) |
35 vcard_email.value = vcard_data.email; | 57 vcard_email.value = vcard_data.email; |
36 vcard_email.disabled = false; | 58 vcard_email.disabled = false; |
37 vcard_bday.value = vcard_data.bday; | 59 vcard_bday.value = vcard_data.bday; |
38 vcard_bday.disabled = false; | 60 vcard_bday.disabled = false; |
39 hideSpinner(spinner_img); | 61 hideSpinner(spinner_img); |
62 getAccessModel(); | |
40 } | 63 } |
41 | 64 |
42 function onVCard4RetrievalError(iq, string) | 65 function onVCard4RetrievalError(iq, string) |
43 { | 66 { |
44 if (!string) { | 67 if (!string) { |
48 console.log(string); | 71 console.log(string); |
49 vcard_fn.disabled = false; | 72 vcard_fn.disabled = false; |
50 vcard_email.disabled = false; | 73 vcard_email.disabled = false; |
51 vcard_bday.disabled = false; | 74 vcard_bday.disabled = false; |
52 hideSpinner(spinner_img); | 75 hideSpinner(spinner_img); |
76 vcard_access.disabled = true; | |
53 } | 77 } |
54 | 78 |
55 function setVCard4() { | 79 function setVCard4() { |
56 // TODO: avoid overriding fields we don’t understand. | 80 // TODO: avoid overriding fields we don’t understand. |
57 const iq = $iq({type: 'set'}) | 81 const iq = $iq({type: 'set'}) |
65 if (vcard_bday.value) | 89 if (vcard_bday.value) |
66 iq.c('bday') | 90 iq.c('bday') |
67 .c('date').t(vcard_bday.value).up().up(); | 91 .c('date').t(vcard_bday.value).up().up(); |
68 connection.sendIQ(iq, onVCard4Changed, onVCard4ChangeError); | 92 connection.sendIQ(iq, onVCard4Changed, onVCard4ChangeError); |
69 displaySpinner(spinner_img); | 93 displaySpinner(spinner_img); |
94 vcard_access.disabled = true; | |
70 } | 95 } |
71 | 96 |
72 vcard_fn.addEventListener('change', setVCard4); | 97 vcard_fn.addEventListener('change', setVCard4); |
73 vcard_email.addEventListener('change', setVCard4); | 98 vcard_email.addEventListener('change', setVCard4); |
74 vcard_bday.addEventListener('change', setVCard4); | 99 vcard_bday.addEventListener('change', setVCard4); |
75 | 100 |
76 function onVCard4Changed(result_iq) | 101 function onVCard4Changed(result_iq) |
77 { | 102 { |
78 console.log('Successfully set vCard4.') | 103 console.log('Successfully set vCard4.') |
79 spinnerOk(spinner_img); | 104 spinnerOk(spinner_img); |
105 getAccessModel(); | |
80 } | 106 } |
81 | 107 |
82 function onVCard4ChangeError(iq) | 108 function onVCard4ChangeError(iq) |
83 { | 109 { |
84 const string = parseErrorIq(iq); | 110 const string = 'Failed to set vCard4: ' + parseErrorIq(iq); |
85 string = 'Failed to set vCard4: ' + string; | |
86 console.log(string); | 111 console.log(string); |
87 spinnerError(spinner_img, string); | 112 spinnerError(spinner_img, string); |
113 vcard_access.disabled = true; | |
88 } | 114 } |
89 | 115 |
90 vcard_access.addEventListener('change', function (evt) { | 116 vcard_access.addEventListener('change', function (evt) { |
91 const iq = configurePEPField('urn:xmpp:vcard4', 'pubsub#access_model', evt.target.value); | 117 const iq = configurePEPField('urn:xmpp:vcard4', 'pubsub#access_model', evt.target.value); |
92 connection.sendIQ(iq, onAccessConfigured, onAccessConfigureError.bind(null, 'PubSub configuration failed.')); | 118 connection.sendIQ(iq, onAccessConfigured, onAccessConfigureError.bind(null, 'PubSub configuration failed.')); |