Mercurial > xmpp-account-manager
comparison avatar.js @ 52:2f45bee88b47
Add pubsub#access_model retrieval for the avatar node.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 23 May 2020 21:24:34 +0200 |
parents | aff7caa10489 |
children | 6d861d881b96 |
comparison
equal
deleted
inserted
replaced
51:c27a4598ec44 | 52:2f45bee88b47 |
---|---|
9 const avatar_file = document.getElementById('avatar-file'); | 9 const avatar_file = document.getElementById('avatar-file'); |
10 const avatar_upload = document.getElementById('avatar-upload'); | 10 const avatar_upload = document.getElementById('avatar-upload'); |
11 const avatar_change = document.getElementById('avatar-change'); | 11 const avatar_change = document.getElementById('avatar-change'); |
12 const avatar_access = document.getElementById('avatar-access'); | 12 const avatar_access = document.getElementById('avatar-access'); |
13 const spinner_img = document.getElementById('avatar-spinner'); | 13 const spinner_img = document.getElementById('avatar-spinner'); |
14 const access_model_spinner_img = document.getElementById('access-model-avatar-spinner'); | 14 const access_spinner_img = document.getElementById('access-model-avatar-spinner'); |
15 | 15 |
16 avatar_img.src = DEFAULT_AVATAR; | 16 avatar_img.src = DEFAULT_AVATAR; |
17 const iq = $iq({type: 'get'}) | 17 const iq = $iq({type: 'get'}) |
18 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) | 18 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) |
19 .c('items', {node: 'urn:xmpp:avatar:metadata'}); | 19 .c('items', {node: 'urn:xmpp:avatar:metadata'}); |
20 connection.sendIQ(iq, onAvatarMetadata, onAvatarRetrievalError.bind(null, 'PubSub metadata query failed.')); | 20 connection.sendIQ(iq, onAvatarMetadata, onAvatarRetrievalError.bind(null, 'PubSub metadata query failed.')); |
21 displaySpinner(spinner_img); | 21 displaySpinner(spinner_img); |
22 getAccessModel(); | |
23 | |
24 function getAccessModel() | |
25 { | |
26 avatar_access.disabled = true; | |
27 displaySpinner(access_spinner_img); | |
28 retrieveConfiguration(connection, 'urn:xmpp:avatar:metadata').then((access_model) => { | |
29 if (access_model !== null) { | |
30 if (access_model === 'open') | |
31 avatar_access.value = 'open'; | |
32 else if (access_model === 'presence') | |
33 avatar_access.value = 'presence'; | |
34 else | |
35 console.log('Unsupported avatar access model: ' + access_model); | |
36 avatar_access.disabled = false; | |
37 } | |
38 hideSpinner(access_spinner_img); | |
39 }, (reason) => { | |
40 console.log('Failed to retrieve avatar configuration: ' + reason); | |
41 hideSpinner(access_spinner_img); | |
42 }); | |
43 } | |
22 | 44 |
23 function onAvatarMetadata(result_iq) | 45 function onAvatarMetadata(result_iq) |
24 { | 46 { |
25 const item = parseXPath(result_iq, './pubsub:pubsub/pubsub:items/pubsub:item'); | 47 const item = parseXPath(result_iq, './pubsub:pubsub/pubsub:items/pubsub:item'); |
26 if (item == null) | 48 if (item == null) |
66 avatar_img.onload = null; | 88 avatar_img.onload = null; |
67 }; | 89 }; |
68 */ | 90 */ |
69 avatar_img.src = url; | 91 avatar_img.src = url; |
70 hideSpinner(spinner_img); | 92 hideSpinner(spinner_img); |
93 getAccessModel(); | |
71 } | 94 } |
72 | 95 |
73 function onAvatarRetrievalError(string) | 96 function onAvatarRetrievalError(string) |
74 { | 97 { |
75 console.log('Failed to retrieve avatar, an empty one is displayed instead: ' + string); | 98 console.log('Failed to retrieve avatar, an empty one is displayed instead: ' + string); |
76 avatar_img.src = DEFAULT_AVATAR; | 99 avatar_img.src = DEFAULT_AVATAR; |
77 hideSpinner(spinner_img); | 100 hideSpinner(spinner_img); |
101 avatar_access.disabled = true; | |
78 } | 102 } |
79 | 103 |
80 avatar_upload.addEventListener('click', function (evt) { | 104 avatar_upload.addEventListener('click', function (evt) { |
81 avatar_file.click(); | 105 avatar_file.click(); |
82 }); | 106 }); |
94 width: avatar_img.naturalWidth, | 118 width: avatar_img.naturalWidth, |
95 height: avatar_img.naturalHeight, | 119 height: avatar_img.naturalHeight, |
96 }); | 120 }); |
97 connection.sendIQ(metadata_iq, onAvatarMetadataUpload, onAvatarUploadError); | 121 connection.sendIQ(metadata_iq, onAvatarMetadataUpload, onAvatarUploadError); |
98 displaySpinner(spinner_img); | 122 displaySpinner(spinner_img); |
123 avatar_access.disabled = true; | |
99 }); | 124 }); |
100 | 125 |
101 function onAvatarMetadataUpload(iq) | 126 function onAvatarMetadataUpload(iq) |
102 { | 127 { |
103 const data_iq = $iq({type: 'set'}) | 128 const data_iq = $iq({type: 'set'}) |
113 { | 138 { |
114 console.log('Avatar successfully uploaded!', iq); | 139 console.log('Avatar successfully uploaded!', iq); |
115 avatar_change.hidden = true; | 140 avatar_change.hidden = true; |
116 avatar_size.innerHTML = ''; | 141 avatar_size.innerHTML = ''; |
117 spinnerOk(spinner_img); | 142 spinnerOk(spinner_img); |
143 getAccessModel(); | |
118 } | 144 } |
119 | 145 |
120 function onAvatarUploadError(iq) | 146 function onAvatarUploadError(iq) |
121 { | 147 { |
122 console.log("onAvatarUploadError", iq); | 148 console.log("onAvatarUploadError", iq); |
123 spinnerError(spinner_img); | 149 spinnerError(spinner_img); |
150 avatar_access.disabled = true; | |
124 } | 151 } |
125 | 152 |
126 avatar_file.addEventListener('change', function (evt) { | 153 avatar_file.addEventListener('change', function (evt) { |
127 const file = evt.target.files[0]; | 154 const file = evt.target.files[0]; |
128 avatar_data.type = file.type; | 155 avatar_data.type = file.type; |
178 } | 205 } |
179 | 206 |
180 avatar_access.addEventListener('change', function (evt) { | 207 avatar_access.addEventListener('change', function (evt) { |
181 const iq = configurePEPField('urn:xmpp:avatar:metadata', 'pubsub#access_model', evt.target.value); | 208 const iq = configurePEPField('urn:xmpp:avatar:metadata', 'pubsub#access_model', evt.target.value); |
182 connection.sendIQ(iq, onAvatarMetadataConfigured, onAvatarConfigureError.bind(null, 'PubSub configuration of metadata failed.')); | 209 connection.sendIQ(iq, onAvatarMetadataConfigured, onAvatarConfigureError.bind(null, 'PubSub configuration of metadata failed.')); |
183 displaySpinner(access_model_spinner_img); | 210 displaySpinner(access_spinner_img); |
184 }); | 211 }); |
185 | 212 |
186 function onAvatarMetadataConfigured(result_iq) | 213 function onAvatarMetadataConfigured(result_iq) |
187 { | 214 { |
188 const iq = configurePEPField('urn:xmpp:avatar:data', 'pubsub#access_model', avatar_access.value); | 215 const iq = configurePEPField('urn:xmpp:avatar:data', 'pubsub#access_model', avatar_access.value); |
190 } | 217 } |
191 | 218 |
192 function onAvatarConfigured(result_iq) | 219 function onAvatarConfigured(result_iq) |
193 { | 220 { |
194 console.log('Successfully set avatar access model.') | 221 console.log('Successfully set avatar access model.') |
195 spinnerOk(access_model_spinner_img); | 222 spinnerOk(access_spinner_img); |
196 } | 223 } |
197 | 224 |
198 function onAvatarConfigureError(string) | 225 function onAvatarConfigureError(string) |
199 { | 226 { |
200 console.log('Failed to configure avatar node: ' + string); | 227 console.log('Failed to configure avatar node: ' + string); |
201 spinnerError(access_model_spinner_img); | 228 spinnerError(access_spinner_img); |
202 } | 229 } |
203 } | 230 } |