annotate mam.js @ 30:9ba4f8cc32f1

Display the returned error in the title of the spinner.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 23 Dec 2018 17:15:38 +0100
parents 6c620e9f7d2c
children 45bd945c5722
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 'use strict';
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 function initMAM(connection) {
20
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
4 const prefs_default = document.getElementById('mam-prefs-default');
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
5 const prefs_always = document.getElementById('mam-prefs-always');
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
6 const prefs_never = document.getElementById('mam-prefs-never');
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 const prefs_spinner = document.getElementById('mam-prefs-spinner');
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8
24
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
9 const mam_retrieve = document.getElementById('mam-retrieve');
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
10 const download_button = document.getElementById('mam-download');
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
11 const retrieve_spinner = document.getElementById('mam-retrieve-spinner');
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
12
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
13 const mam_data = [];
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
14
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
15 download_button.disabled = true;
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
16
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 const iq = $iq({type: 'get'})
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 .c('prefs', {xmlns: NS.mam});
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 connection.sendIQ(iq, onMAMPrefs, onMAMPrefsError.bind(null, 'query failed.'));
18
3c02cbced2df Disable default MAM prefs until we received the iq result.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
20 displaySpinner(prefs_spinner);
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 function onMAMPrefs(result_iq)
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 {
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 const prefs = parseXPath(result_iq, './mam:prefs');
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 if (prefs == null)
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 return onMAMPrefsError('server error.');
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 const default_ = prefs.getAttributeNS(null, 'default');
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 prefs_default.value = default_;
18
3c02cbced2df Disable default MAM prefs until we received the iq result.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
29 prefs_default.disabled = false;
3c02cbced2df Disable default MAM prefs until we received the iq result.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
30 hideSpinner(prefs_spinner);
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 const always = parseXPath(prefs, './mam:always/mam:jid', XPathResult.ORDERED_NODE_ITERATOR_TYPE);
20
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
32 const always_array = [];
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 while (true) {
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 const item = always.iterateNext();
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 if (!item)
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 break;
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 const jid = item.textContent;
20
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
38 always_array.push(jid);
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 }
20
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
40 prefs_always.value = always_array.join('\n');
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 const never = parseXPath(prefs, './mam:never/mam:jid', XPathResult.ORDERED_NODE_ITERATOR_TYPE);
20
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
42 const never_array = [];
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 while (true) {
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 const item = never.iterateNext();
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 if (!item)
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46 break;
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 const jid = item.textContent;
20
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
48 never_array.push(jid);
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 }
20
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
50 prefs_never.value = never_array.join('\n');
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 }
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 function onMAMPrefsError(string)
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 {
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55 console.log('Failed to retrieve your message archiving preferences: ' + string);
18
3c02cbced2df Disable default MAM prefs until we received the iq result.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
56 spinnerError(prefs_spinner);
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57 }
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58
20
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
59 function submitPrefs(evt) {
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 const iq = $iq({type: 'set'})
20
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
61 .c('prefs', {xmlns: NS.mam, 'default': prefs_default.value})
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
62 .c('always');
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
63 const always_array = prefs_always.value.split('\n');
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
64 for (let line of always_array) {
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
65 iq.c('jid').t(line).up();
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
66 }
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
67 iq.up().c('never');
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
68 const never_array = prefs_never.value.split('\n');
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
69 for (let line of never_array) {
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
70 iq.c('jid').t(line).up();
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
71 }
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 connection.sendIQ(iq, onPrefsSet, onPrefsError);
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 displaySpinner(prefs_spinner);
20
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
74 }
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
75
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
76 prefs_default.addEventListener('change', submitPrefs);
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
77 prefs_always.addEventListener('blur', submitPrefs);
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
78 prefs_never.addEventListener('blur', submitPrefs);
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 function onPrefsSet(iq)
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81 {
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82 console.log('MAM preferences successfully updated.');
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 spinnerOk(prefs_spinner);
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 }
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 function onPrefsError(iq)
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 {
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 console.log('Error while changing MAM preferences.');
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 spinnerError(prefs_spinner);
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 }
24
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
91
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
92 mam_retrieve.addEventListener('click', function (evt) {
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
93 connection.mam.query(null, {
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
94 onMessage: function (message, delay, id) {
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
95 console.log('Got a MAM message:', message, delay, id);
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
96 const result = document.createElementNS(NS.mam, 'result');
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
97 result.setAttributeNS(null, 'id', id);
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
98 const forwarded = document.createElementNS(NS.forward, 'forwarded');
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
99 forwarded.appendChild(delay);
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
100 forwarded.appendChild(message);
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
101 result.appendChild(forwarded);
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
102 mam_data.push(result);
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
103 },
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
104 onComplete: function () {
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
105 console.log('Received all messages, you can now download a backup of your archive.');
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
106 download_button.disabled = false;
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
107 spinnerOk(retrieve_spinner);
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
108 },
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
109 });
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
110 displaySpinner(retrieve_spinner);
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
111 });
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
112
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
113 download_button.addEventListener('click', function (evt) {
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
114 // TODO: extend XEP-0227 with MAM support.
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
115 const messages = document.createElementNS('https://prosody.im/protocol/pie-mam', 'message-archive');
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
116 for (let result of mam_data)
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
117 messages.appendChild(result);
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
118 const blob = new Blob([messages.outerHTML], {type: 'text/xml'});
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
119 const link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
120 link.hidden = false;
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
121 link.href = URL.createObjectURL(blob);
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
122 link.download = Strophe.getBareJidFromJid(connection.jid) + '-archive.xml';
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
123 console.log(link.download);
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
124 document.body.appendChild(link);
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
125 link.click();
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
126 URL.revokeObjectURL(link.href);
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
127 document.body.removeChild(link);
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 20
diff changeset
128 });
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129 }