annotate mam.js @ 63:ee1df80a1715 default tip

Nicer-looking input form
author mathieui
date Sun, 24 May 2020 14:19:29 +0200
parents 78c873be0caa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
60
6d861d881b96 Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 34
diff changeset
1 // SPDX-License-Identifier: AGPL-3.0-only
6d861d881b96 Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 34
diff changeset
2 /*
6d861d881b96 Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 34
diff changeset
3 * Copyright © 2018-2020 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
6d861d881b96 Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 34
diff changeset
4 * Copyright © 2020 Mathieu Pasquet <mathieui@mathieui.net>
6d861d881b96 Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 34
diff changeset
5 *
6d861d881b96 Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 34
diff changeset
6 * Released under GNU AGPL v3 only, read the file 'LICENSE' for more information.
6d861d881b96 Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 34
diff changeset
7 */
6d861d881b96 Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 34
diff changeset
8
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 'use strict';
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 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
12 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
13 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
14 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
15 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
16
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
17 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
18 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
19 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
20
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
21 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
22
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
23 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
24
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 const iq = $iq({type: 'get'})
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 .c('prefs', {xmlns: NS.mam});
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 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
28 displaySpinner(prefs_spinner);
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 function onMAMPrefs(result_iq)
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 {
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32 const prefs = parseXPath(result_iq, './mam:prefs');
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 if (prefs == null)
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 return onMAMPrefsError('server error.');
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 const default_ = prefs.getAttributeNS(null, 'default');
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 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
37 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
38 hideSpinner(prefs_spinner);
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 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
40 const always_array = [];
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 while (true) {
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 const item = always.iterateNext();
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 if (!item)
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 break;
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 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
46 always_array.push(jid);
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 }
20
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
48 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
49 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
50 const never_array = [];
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 while (true) {
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 const item = never.iterateNext();
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 if (!item)
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 break;
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55 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
56 never_array.push(jid);
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57 }
20
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
58 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
59 }
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 function onMAMPrefsError(string)
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 {
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 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
64 spinnerError(prefs_spinner);
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 }
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66
20
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
67 function submitPrefs(evt) {
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 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
69 .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
70 .c('always');
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
71 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
72 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
73 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
74 }
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
75 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
76 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
77 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
78 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
79 }
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 connection.sendIQ(iq, onPrefsSet, onPrefsError);
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81 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
82 }
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
83
46660687924b Also set and get always and never lists from MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
84 prefs_default.addEventListener('change', submitPrefs);
34
45bd945c5722 Change all blur events to change, prevents a stanza when no change occured.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 24
diff changeset
85 prefs_always.addEventListener('change', submitPrefs);
45bd945c5722 Change all blur events to change, prevents a stanza when no change occured.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 24
diff changeset
86 prefs_never.addEventListener('change', submitPrefs);
17
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 function onPrefsSet(iq)
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 {
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 console.log('MAM preferences successfully updated.');
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 spinnerOk(prefs_spinner);
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92 }
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94 function onPrefsError(iq)
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 {
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96 console.log('Error while changing MAM preferences.');
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97 spinnerError(prefs_spinner);
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 }
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
99
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 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
101 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
102 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
103 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
104 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
105 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
106 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
107 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
108 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
109 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
110 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
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 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
113 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
114 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
115 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
116 },
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 });
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 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
119 });
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
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 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
122 // TODO: extend XEP-0227 with MAM support.
61
78c873be0caa Remove Prosody specifics in strings and namespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 60
diff changeset
123 const messages = document.createElementNS('https://linkmauve.fr/protocol/pie-mam', 'message-archive');
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
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131 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
132 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
133 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
134 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
135 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
136 });
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
137 }