diff 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
line wrap: on
line diff
--- a/avatar.js
+++ b/avatar.js
@@ -9,6 +9,7 @@ function initAvatar(connection) {
     const avatar_file = document.getElementById('avatar-file');
     const avatar_upload = document.getElementById('avatar-upload');
     const avatar_change = document.getElementById('avatar-change');
+    const avatar_access = document.getElementById('avatar-access');
 
     avatar_img.src = DEFAULT_AVATAR;
     const iq = $iq({type: 'get'})
@@ -168,4 +169,32 @@ function initAvatar(connection) {
         }
         return [bytes, unit];
     }
+
+    avatar_access.addEventListener('change', function (evt) {
+        const iq = $iq({type: 'set'})
+            .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub#owner'})
+                .c('configure', {node: 'urn:xmpp:avatar:metadata'})
+                    .c('x', {xmlns: 'jabber:x:data', type: 'submit'})
+                        .c('field', {'var': 'FORM_TYPE', type: 'hidden'})
+                            .c('value')
+                                .t('http://jabber.org/protocol/pubsub#node_config')
+                                .up()
+                            .up()
+                        .c('field', {'var': 'pubsub#access_model'})
+                            .c('value')
+                                .t(evt.target.value)
+                                .up()
+                            .up()
+        connection.sendIQ(iq, onAvatarConfigured, onAvatarConfigureError.bind(null, 'PubSub configuration failed.'));
+    });
+
+    function onAvatarConfigured(result_iq)
+    {
+        console.log('Successfully set avatar access model.')
+    }
+
+    function onAvatarConfigureError(string)
+    {
+        console.log('Failed to configure avatar node: ' + string);
+    }
 }