Skip to content

Commit 4ff9f77

Browse files
committed
Create strophe.mam.v0.3.js
the standards for XEP-0313 have changed, this new code makes MAM work as intended with servers (such as prosody) that have migrated to the new standard. Could use some improvements like preferences, but in my case i don't need them yet.
1 parent 40f21bd commit 4ff9f77

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

mam/strophe.mam.v0.3.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* XEP-0313: Message Archive Management
2+
* Copyright (C) 2012 Kim Alvefur
3+
*
4+
* This file is MIT/X11 licensed. Please see the
5+
* LICENSE.txt file in the source package for more information.
6+
*
7+
* TODO:
8+
* Get RSM from the reply
9+
* Clean remove onMessage handler afterwards
10+
* queryid?
11+
*
12+
*/
13+
14+
Strophe.addConnectionPlugin('mam', {
15+
_c: null,
16+
_p: [ "with", "start", "end" ],
17+
init: function (conn) {
18+
this._c = conn;
19+
Strophe.addNamespace('MAM', 'urn:xmpp:mam:0');
20+
},
21+
query: function (jid, options) {
22+
var _p = this._p;
23+
var attr = {
24+
type:"set",
25+
id:jid
26+
};
27+
var mamAttr = {xmlns: Strophe.NS.MAM};
28+
var iq = $iq(attr).c("query", mamAttr).c('x',{xmlns:'jabber:x:data'});
29+
30+
iq.c('field',{var:"FORM_TYPE"}).c('value').t("urn:xmpp:mam:0").up().up();
31+
for (i = 0; i < this._p.length; i++) {
32+
var pn = _p[i];
33+
var p = options[pn];
34+
delete options[pn];
35+
if (!!p) {
36+
var f
37+
iq.c('field',{var:pn}).c('value').t(p).up().up();
38+
}
39+
}
40+
iq.up();
41+
42+
var onMessage = options["onMessage"];
43+
delete options['onMessage'];
44+
var onComplete = options["onComplete"];
45+
delete options['onComplete'];
46+
iq.cnode(new Strophe.RSM(options).toXML());
47+
48+
this._c.addHandler(onMessage, Strophe.NS.MAM, "message", null);
49+
return this._c.sendIQ(iq, onComplete);
50+
}
51+
});

0 commit comments

Comments
 (0)