comparison avatar.js @ 2:db033e5eabcb

Add pubsub#access_model configuration for avatars.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 22 Dec 2018 01:21:03 +0100
parents d6df73b466f6
children 5aa1bf7154b0
comparison
equal deleted inserted replaced
1:d6df73b466f6 2:db033e5eabcb
7 const avatar_img = document.getElementById('avatar'); 7 const avatar_img = document.getElementById('avatar');
8 const avatar_size = document.getElementById('avatar-size'); 8 const avatar_size = document.getElementById('avatar-size');
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 13
13 avatar_img.src = DEFAULT_AVATAR; 14 avatar_img.src = DEFAULT_AVATAR;
14 const iq = $iq({type: 'get'}) 15 const iq = $iq({type: 'get'})
15 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) 16 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
16 .c('items', {node: 'urn:xmpp:avatar:metadata'}); 17 .c('items', {node: 'urn:xmpp:avatar:metadata'});
166 bytes /= 1024; 167 bytes /= 1024;
167 unit = 'TiB'; 168 unit = 'TiB';
168 } 169 }
169 return [bytes, unit]; 170 return [bytes, unit];
170 } 171 }
172
173 avatar_access.addEventListener('change', function (evt) {
174 const iq = $iq({type: 'set'})
175 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub#owner'})
176 .c('configure', {node: 'urn:xmpp:avatar:metadata'})
177 .c('x', {xmlns: 'jabber:x:data', type: 'submit'})
178 .c('field', {'var': 'FORM_TYPE', type: 'hidden'})
179 .c('value')
180 .t('http://jabber.org/protocol/pubsub#node_config')
181 .up()
182 .up()
183 .c('field', {'var': 'pubsub#access_model'})
184 .c('value')
185 .t(evt.target.value)
186 .up()
187 .up()
188 connection.sendIQ(iq, onAvatarConfigured, onAvatarConfigureError.bind(null, 'PubSub configuration failed.'));
189 });
190
191 function onAvatarConfigured(result_iq)
192 {
193 console.log('Successfully set avatar access model.')
194 }
195
196 function onAvatarConfigureError(string)
197 {
198 console.log('Failed to configure avatar node: ' + string);
199 }
171 } 200 }