-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathstrophe.mam.js
More file actions
66 lines (61 loc) · 2.05 KB
/
strophe.mam.js
File metadata and controls
66 lines (61 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* XEP-0313: Message Archive Management
* Copyright (C) 2012 Kim Alvefur
*
* This file is MIT/X11 licensed. Please see the
* LICENSE.txt file in the source package for more information.
*
* Modified by: Chris Tunbridge (github.com/Destreyf/)
* Updated to support v0.3 of the XMPP XEP-0313 standard
* http://xmpp.org/extensions/xep-0313.html
*
*/
//import { $iq, Strophe } from 'strophe.js'; NOTE: Can make issues on some systems
Strophe.addConnectionPlugin('mam', {
_c: null,
_p: [ 'with', 'start', 'end' ],
init: function (conn) {
this._c = conn;
Strophe.addNamespace('MAM', 'urn:xmpp:mam:2');
},
query: function (jid, options) {
var _p = this._p;
var attr = {
type:'set',
to:jid
};
options = options || {};
var mamAttr = {xmlns: Strophe.NS.MAM};
if (!!options.queryid) {
mamAttr.queryid = options.queryid;
delete options.queryid;
}
var iq = $iq(attr).c('query', mamAttr).c('x',{xmlns:'jabber:x:data', type:'submit'});
var ns = Strophe.NS.MAM;
if ( options.oldVersion )
ns = 'urn:xmpp:mam:1';
iq.c('field',{var:'FORM_TYPE', type:'hidden'}).c('value').t(ns).up().up();
var i;
for (i = 0; i < this._p.length; i++) {
var pn = _p[i];
var p = options[pn];
delete options[pn];
if (!!p) {
iq.c('field',{var:pn}).c('value').t(p).up().up();
}
}
iq.up();
var onMessage = options.onMessage;
delete options.onMessage;
var onComplete = options.onComplete;
delete options.onComplete;
var onError = options.onError;
delete options.onError;
iq.cnode(new Strophe.RSM(options).toXML());
var _c = this._c;
var handler = _c.addHandler(onMessage, Strophe.NS.MAM, 'message', null);
return this._c.sendIQ(iq, function(){
_c.deleteHandler(handler);
onComplete.apply(this, arguments);
},onError);
}
});