Mercurial > xmpp-account-manager
annotate strophe.mam.js @ 31:e561bdd81777
Display better vCard4 errors.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 23 Dec 2018 18:20:17 +0100 |
parents | 6c620e9f7d2c |
children | 599b324fac2b |
rev | line source |
---|---|
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:
diff
changeset
|
1 /* XEP-0313: Message Archive Management |
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:
diff
changeset
|
2 * Copyright (C) 2012 Kim Alvefur |
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:
diff
changeset
|
3 * Copyright (C) 2018 Emmanuel Gil Peyrot |
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:
diff
changeset
|
4 * |
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:
diff
changeset
|
5 * This file is MIT/X11 licensed. Please see the |
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:
diff
changeset
|
6 * LICENSE.txt file in the source package for more information. |
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:
diff
changeset
|
7 * |
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:
diff
changeset
|
8 * Modified by: Chris Tunbridge (github.com/Destreyf/) |
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:
diff
changeset
|
9 * Updated to support v0.3 of the XMPP XEP-0313 standard |
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:
diff
changeset
|
10 * http://xmpp.org/extensions/xep-0313.html |
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:
diff
changeset
|
11 * |
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:
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:
diff
changeset
|
13 //import { $iq, Strophe } from 'strophe.js'; |
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:
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:
diff
changeset
|
15 Strophe.addConnectionPlugin('mam', { |
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:
diff
changeset
|
16 _c: 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:
diff
changeset
|
17 _p: [ 'with', 'start', 'end' ], |
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:
diff
changeset
|
18 init: function (conn) { |
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:
diff
changeset
|
19 this._c = conn; |
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:
diff
changeset
|
20 Strophe.addNamespace('MAM', 'urn:xmpp:mam:2'); |
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:
diff
changeset
|
21 Strophe.addNamespace('Forward', 'urn:xmpp:forward:0'); |
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:
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:
diff
changeset
|
23 query: function (jid, options) { |
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:
diff
changeset
|
24 var _c = this._c; |
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:
diff
changeset
|
25 var _p = this._p; |
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:
diff
changeset
|
26 var attr = { |
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:
diff
changeset
|
27 type:'set', |
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:
diff
changeset
|
28 to:jid |
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:
diff
changeset
|
29 }; |
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:
diff
changeset
|
30 options = options || {}; |
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:
diff
changeset
|
31 var queryid = options.queryid; |
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:
diff
changeset
|
32 if (queryid) { |
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:
diff
changeset
|
33 delete options.queryid; |
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:
diff
changeset
|
34 } else { |
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:
diff
changeset
|
35 queryid = _c.getUniqueId(); |
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:
diff
changeset
|
36 } |
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:
diff
changeset
|
37 var iq = $iq(attr).c('query', {xmlns: Strophe.NS.MAM, queryid: queryid}).c('x',{xmlns:'jabber:x:data', type:'submit'}); |
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:
diff
changeset
|
38 |
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:
diff
changeset
|
39 iq.c('field',{var:'FORM_TYPE', type:'hidden'}).c('value').t(Strophe.NS.MAM).up().up(); |
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:
diff
changeset
|
40 for (var i = 0; i < _p.length; i++) { |
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:
diff
changeset
|
41 var pn = _p[i]; |
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:
diff
changeset
|
42 var p = options[pn]; |
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:
diff
changeset
|
43 delete options[pn]; |
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:
diff
changeset
|
44 if (p) { |
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:
diff
changeset
|
45 iq.c('field',{var:pn}).c('value').t(p).up().up(); |
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:
diff
changeset
|
46 } |
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:
diff
changeset
|
47 } |
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:
diff
changeset
|
48 iq.up(); |
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:
diff
changeset
|
49 |
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:
diff
changeset
|
50 var onMessage = options.onMessage; |
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:
diff
changeset
|
51 delete options.onMessage; |
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:
diff
changeset
|
52 var onComplete = options.onComplete; |
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:
diff
changeset
|
53 delete options.onComplete; |
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:
diff
changeset
|
54 iq.cnode(new Strophe.RSM(options).toXML()); |
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:
diff
changeset
|
55 |
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:
diff
changeset
|
56 var handler = _c.addHandler(function (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:
diff
changeset
|
57 // TODO: check the emitter too! |
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:
diff
changeset
|
58 var result = message.firstChild; |
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:
diff
changeset
|
59 if (!result || result.namespaceURI !== Strophe.NS.MAM || result.localName !== 'result' || result.getAttributeNS(null, 'queryid') !== queryid) |
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:
diff
changeset
|
60 return 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:
diff
changeset
|
61 var id = result.getAttributeNS(null, '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:
diff
changeset
|
62 var forwarded = result.firstChild; |
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:
diff
changeset
|
63 if (!forwarded || forwarded.namespaceURI !== Strophe.NS.Forward || forwarded.localName !== '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:
diff
changeset
|
64 return 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:
diff
changeset
|
65 var delay = 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:
diff
changeset
|
66 var childMessage = 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:
diff
changeset
|
67 for (var child of forwarded.childNodes.values()) { |
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:
diff
changeset
|
68 if (child.namespaceURI === 'urn:xmpp:delay' && child.localName === 'delay' && delay === 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:
diff
changeset
|
69 delay = child; |
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:
diff
changeset
|
70 else if (child.namespaceURI === 'jabber:client' && child.localName === 'message' && childMessage === 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:
diff
changeset
|
71 childMessage = child; |
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:
diff
changeset
|
72 } |
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:
diff
changeset
|
73 if (childMessage !== null && delay !== 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:
diff
changeset
|
74 onMessage(childMessage, 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:
diff
changeset
|
75 return 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:
diff
changeset
|
76 }, Strophe.NS.MAM, 'message', 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:
diff
changeset
|
77 return _c.sendIQ(iq, 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:
diff
changeset
|
78 _c.deleteHandler(handler); |
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:
diff
changeset
|
79 onComplete.apply(this, arguments); |
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:
diff
changeset
|
80 }); |
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:
diff
changeset
|
81 } |
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:
diff
changeset
|
82 }); |