changeset 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 9ada1963558c
children 010b905a74d4
files index.xhtml vcard.js
diffstat 2 files changed, 29 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/index.xhtml
+++ b/index.xhtml
@@ -104,7 +104,7 @@
 </p>
 <p>
 <label>{% trans 'Who can see your personal information?' %}<br/>
-<select id="vcard-access">
+<select class="form-control" id="vcard-access" disabled="">
 <option value="open">{% trans 'Anyone' %}</option>
 <option value="presence">{% trans 'Only your contacts' %}</option>
 </select></label> <img width="24" height="24" id="vcard-access-spinner" hidden=""/>
--- a/vcard.js
+++ b/vcard.js
@@ -16,6 +16,28 @@ function initVCard(connection) {
                 .c('item', {id: 'current'});
     connection.sendIQ(iq, onVCard4, onVCard4RetrievalError);
     displaySpinner(spinner_img);
+    getAccessModel();
+
+    function getAccessModel()
+    {
+        vcard_access.disabled = true;
+        displaySpinner(access_spinner_img);
+        retrieveConfiguration(connection, 'urn:xmpp:vcard4').then((access_model) => {
+            if (access_model !== null) {
+                if (access_model === 'open')
+                    vcard_access.value = 'open';
+                else if (access_model === 'presence')
+                    vcard_access.value = 'presence';
+                else
+                    console.log('Unsupported vCard4 access model: ' + access_model);
+                vcard_access.disabled = false;
+            }
+            hideSpinner(access_spinner_img);
+        }, (reason) => {
+            console.log('Failed to retrieve vCard4 configuration:', reason);
+            hideSpinner(access_spinner_img);
+        });
+    }
 
     function onVCard4(result_iq)
     {
@@ -37,6 +59,7 @@ function initVCard(connection) {
         vcard_bday.value = vcard_data.bday;
         vcard_bday.disabled = false;
         hideSpinner(spinner_img);
+        getAccessModel();
     }
 
     function onVCard4RetrievalError(iq, string)
@@ -50,6 +73,7 @@ function initVCard(connection) {
         vcard_email.disabled = false;
         vcard_bday.disabled = false;
         hideSpinner(spinner_img);
+        vcard_access.disabled = true;
     }
 
     function setVCard4() {
@@ -67,6 +91,7 @@ function initVCard(connection) {
                 .c('date').t(vcard_bday.value).up().up();
         connection.sendIQ(iq, onVCard4Changed, onVCard4ChangeError);
         displaySpinner(spinner_img);
+        vcard_access.disabled = true;
     }
 
     vcard_fn.addEventListener('change', setVCard4);
@@ -77,14 +102,15 @@ function initVCard(connection) {
     {
         console.log('Successfully set vCard4.')
         spinnerOk(spinner_img);
+        getAccessModel();
     }
 
     function onVCard4ChangeError(iq)
     {
-        const string = parseErrorIq(iq);
-        string = 'Failed to set vCard4: ' + string;
+        const string = 'Failed to set vCard4: ' + parseErrorIq(iq);
         console.log(string);
         spinnerError(spinner_img, string);
+        vcard_access.disabled = true;
     }
 
     vcard_access.addEventListener('change', function (evt) {