Mercurial > xmpp-account-manager
comparison strophe.rsm.js @ 24:6c620e9f7d2c
Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 23 Dec 2018 15:39:51 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
23:e99984564b17 | 24:6c620e9f7d2c |
---|---|
1 //import { $build, Strophe } from 'strophe.js'; | |
2 | |
3 Strophe.addNamespace('RSM', 'http://jabber.org/protocol/rsm'); | |
4 | |
5 Strophe.RSM = function(options) { | |
6 this.attribs = ['max', 'first', 'last', 'after', 'before', 'index', 'count']; | |
7 | |
8 if (typeof options.xml != 'undefined') { | |
9 this.fromXMLElement(options.xml); | |
10 } else { | |
11 for (var ii = 0; ii < this.attribs.length; ii++) { | |
12 var attrib = this.attribs[ii]; | |
13 this[attrib] = options[attrib]; | |
14 } | |
15 } | |
16 }; | |
17 | |
18 Strophe.RSM.prototype = { | |
19 toXML: function() { | |
20 var xml = $build('set', {xmlns: Strophe.NS.RSM}); | |
21 for (var ii = 0; ii < this.attribs.length; ii++) { | |
22 var attrib = this.attribs[ii]; | |
23 if (typeof this[attrib] != 'undefined') { | |
24 xml = xml.c(attrib).t(this[attrib].toString()).up(); | |
25 } | |
26 } | |
27 return xml.tree(); | |
28 }, | |
29 | |
30 next: function(max) { | |
31 var newSet = new Strophe.RSM({max: max, after: this.last}); | |
32 return newSet; | |
33 }, | |
34 | |
35 previous: function(max) { | |
36 var newSet = new Strophe.RSM({max: max, before: this.first}); | |
37 return newSet; | |
38 }, | |
39 | |
40 fromXMLElement: function(xmlElement) { | |
41 for (var ii = 0; ii < this.attribs.length; ii++) { | |
42 var attrib = this.attribs[ii]; | |
43 var elem = xmlElement.getElementsByTagName(attrib)[0]; | |
44 if (typeof elem != 'undefined' && elem !== null) { | |
45 this[attrib] = Strophe.getText(elem); | |
46 if (attrib == 'first') { | |
47 this.index = elem.getAttribute('index'); | |
48 } | |
49 } | |
50 } | |
51 } | |
52 }; |