Mercurial > xmpp-account-manager
changeset 20:46660687924b
Also set and get always and never lists from MAM prefs.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 22 Dec 2018 20:12:19 +0100 |
parents | bde4f0bbfe69 |
children | cd35420457ac |
files | index.xhtml mam.js |
diffstat | 2 files changed, 29 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/index.xhtml +++ b/index.xhtml @@ -139,7 +139,7 @@ Enter your nickname, so people you know </div> <div class="col-sm-8"> <p> -<label>Which messages to store in your archive? <select id="mam-default" disabled=""> +<label>Which messages to store in your archive? <select id="mam-prefs-default" disabled=""> <option value="always">All messages</option> <option value="never">No messages</option> <option value="roster">Messages from your contacts only</option> @@ -151,8 +151,8 @@ Enter your nickname, so people you know <th>Never:</th> </tr> <tr> -<td><textarea disabled=""/></td> -<td><textarea disabled=""/></td> +<td><textarea id="mam-prefs-always"/></td> +<td><textarea id="mam-prefs-never"/></td> </tr> </table> <button disabled="">View my message archive</button><br/>
--- a/mam.js +++ b/mam.js @@ -1,7 +1,9 @@ 'use strict'; function initMAM(connection) { - const prefs_default = document.getElementById('mam-default'); + const prefs_default = document.getElementById('mam-prefs-default'); + const prefs_always = document.getElementById('mam-prefs-always'); + const prefs_never = document.getElementById('mam-prefs-never'); const prefs_spinner = document.getElementById('mam-prefs-spinner'); const iq = $iq({type: 'get'}) @@ -19,21 +21,25 @@ function initMAM(connection) { prefs_default.disabled = false; hideSpinner(prefs_spinner); const always = parseXPath(prefs, './mam:always/mam:jid', XPathResult.ORDERED_NODE_ITERATOR_TYPE); + const always_array = []; while (true) { const item = always.iterateNext(); if (!item) break; const jid = item.textContent; - console.log(jid); + always_array.push(jid); } + prefs_always.value = always_array.join('\n'); const never = parseXPath(prefs, './mam:never/mam:jid', XPathResult.ORDERED_NODE_ITERATOR_TYPE); + const never_array = []; while (true) { const item = never.iterateNext(); if (!item) break; const jid = item.textContent; - console.log(jid); + never_array.push(jid); } + prefs_never.value = never_array.join('\n'); } function onMAMPrefsError(string) @@ -42,14 +48,26 @@ function initMAM(connection) { spinnerError(prefs_spinner); } - prefs_default.addEventListener('change', function (evt) { - const value = evt.target.value; - + function submitPrefs(evt) { const iq = $iq({type: 'set'}) - .c('prefs', {xmlns: NS.mam, 'default': prefs_default.value}); + .c('prefs', {xmlns: NS.mam, 'default': prefs_default.value}) + .c('always'); + const always_array = prefs_always.value.split('\n'); + for (let line of always_array) { + iq.c('jid').t(line).up(); + } + iq.up().c('never'); + const never_array = prefs_never.value.split('\n'); + for (let line of never_array) { + iq.c('jid').t(line).up(); + } connection.sendIQ(iq, onPrefsSet, onPrefsError); displaySpinner(prefs_spinner); - }); + } + + prefs_default.addEventListener('change', submitPrefs); + prefs_always.addEventListener('blur', submitPrefs); + prefs_never.addEventListener('blur', submitPrefs); function onPrefsSet(iq) {