changeset 35:084202870d76

Add nickname access model configuration.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 23 Dec 2018 21:41:32 +0100
parents 45bd945c5722
children 599b324fac2b
files index.xhtml nickname.js
diffstat 2 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/index.xhtml
+++ b/index.xhtml
@@ -68,6 +68,13 @@
 <p>
 Enter your nickname, so people you know can recognize you.
 </p>
+<p>
+<label>Who can see your nickname?<br/>
+<select id="nick-access">
+<option value="open">Anyone (pick this if you use public groupchats)</option>
+<option value="presence">Only your contacts</option>
+</select></label> <img width="24" height="24" id="nick-access-spinner" hidden=""/>
+</p>
 </div>
 </div>
 
--- a/nickname.js
+++ b/nickname.js
@@ -2,7 +2,9 @@
 
 function initNickname(connection) {
     const nick_input = document.getElementById('nick');
+    const nick_access = document.getElementById('nick-access');
     const spinner_img = document.getElementById('nick-spinner');
+    const access_spinner_img = document.getElementById('nick-access-spinner');
 
     const iq = $iq({type: 'get'})
         .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
@@ -49,4 +51,23 @@ function initNickname(connection) {
         console.log("onNicknameChangeError", iq);
         spinnerError(spinner_img);
     }
+
+    nick_access.addEventListener('change', function (evt) {
+        const iq = configurePEPField('http://jabber.org/protocol/nick', 'pubsub#access_model', evt.target.value);
+        connection.sendIQ(iq, onNicknameConfigured, onNicknameConfigureError);
+        displaySpinner(access_spinner_img);
+    });
+
+    function onNicknameConfigured(iq)
+    {
+        console.log('Successfully set nickname access model.')
+        spinnerOk(access_spinner_img);
+    }
+
+    function onNicknameConfigureError(iq)
+    {
+        const string = 'Failed to configure nick node: ' + parseErrorIq(iq);
+        console.log(string);
+        spinnerError(access_spinner_img, string);
+    }
 }