Mercurial > xmpp-account-manager
comparison mam.js @ 17:07543f7f5e89
Retrieve and change the default MAM prefs.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 22 Dec 2018 19:42:42 +0100 |
parents | |
children | 3c02cbced2df |
comparison
equal
deleted
inserted
replaced
16:c3e2e0c62486 | 17:07543f7f5e89 |
---|---|
1 'use strict'; | |
2 | |
3 function initMAM(connection) { | |
4 const prefs_default = document.getElementById('mam-default'); | |
5 const prefs_spinner = document.getElementById('mam-prefs-spinner'); | |
6 | |
7 const iq = $iq({type: 'get'}) | |
8 .c('prefs', {xmlns: NS.mam}); | |
9 connection.sendIQ(iq, onMAMPrefs, onMAMPrefsError.bind(null, 'query failed.')); | |
10 | |
11 function onMAMPrefs(result_iq) | |
12 { | |
13 const prefs = parseXPath(result_iq, './mam:prefs'); | |
14 if (prefs == null) | |
15 return onMAMPrefsError('server error.'); | |
16 const default_ = prefs.getAttributeNS(null, 'default'); | |
17 prefs_default.value = default_; | |
18 const always = parseXPath(prefs, './mam:always/mam:jid', XPathResult.ORDERED_NODE_ITERATOR_TYPE); | |
19 while (true) { | |
20 const item = always.iterateNext(); | |
21 if (!item) | |
22 break; | |
23 const jid = item.textContent; | |
24 console.log(jid); | |
25 } | |
26 const never = parseXPath(prefs, './mam:never/mam:jid', XPathResult.ORDERED_NODE_ITERATOR_TYPE); | |
27 while (true) { | |
28 const item = never.iterateNext(); | |
29 if (!item) | |
30 break; | |
31 const jid = item.textContent; | |
32 console.log(jid); | |
33 } | |
34 } | |
35 | |
36 function onMAMPrefsError(string) | |
37 { | |
38 console.log('Failed to retrieve your message archiving preferences: ' + string); | |
39 } | |
40 | |
41 prefs_default.addEventListener('change', function (evt) { | |
42 const value = evt.target.value; | |
43 | |
44 const iq = $iq({type: 'set'}) | |
45 .c('prefs', {xmlns: NS.mam, 'default': prefs_default.value}); | |
46 connection.sendIQ(iq, onPrefsSet, onPrefsError); | |
47 displaySpinner(prefs_spinner); | |
48 }); | |
49 | |
50 function onPrefsSet(iq) | |
51 { | |
52 console.log('MAM preferences successfully updated.'); | |
53 spinnerOk(prefs_spinner); | |
54 } | |
55 | |
56 function onPrefsError(iq) | |
57 { | |
58 console.log('Error while changing MAM preferences.'); | |
59 spinnerError(prefs_spinner); | |
60 } | |
61 } |