Mercurial > xmpp-account-manager
annotate strophe.rsm.js @ 30:9ba4f8cc32f1
Display the returned error in the title of the spinner.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 23 Dec 2018 17:15:38 +0100 |
parents | 6c620e9f7d2c |
children |
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 //import { $build, 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
|
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
|
3 Strophe.addNamespace('RSM', 'http://jabber.org/protocol/rsm'); |
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 Strophe.RSM = function(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
|
6 this.attribs = ['max', 'first', 'last', 'after', 'before', 'index', 'count']; |
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 if (typeof options.xml != 'undefined') { |
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 this.fromXMLElement(options.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:
diff
changeset
|
10 } 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
|
11 for (var ii = 0; ii < this.attribs.length; ii++) { |
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 var attrib = this.attribs[ii]; |
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 this[attrib] = options[attrib]; |
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 } |
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 }; |
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 |
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 Strophe.RSM.prototype = { |
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 toXML: 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
|
20 var xml = $build('set', {xmlns: Strophe.NS.RSM}); |
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 for (var ii = 0; ii < this.attribs.length; ii++) { |
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 var attrib = this.attribs[ii]; |
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 if (typeof this[attrib] != 'undefined') { |
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 xml = xml.c(attrib).t(this[attrib].toString()).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
|
25 } |
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 } |
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 return xml.tree(); |
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 }, |
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 next: function(max) { |
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 newSet = new Strophe.RSM({max: max, after: this.last}); |
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 return newSet; |
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 }, |
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 |
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 previous: function(max) { |
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 var newSet = new Strophe.RSM({max: max, before: this.first}); |
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 return newSet; |
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 |
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 fromXMLElement: function(xmlElement) { |
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 for (var ii = 0; ii < this.attribs.length; ii++) { |
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 attrib = this.attribs[ii]; |
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 var elem = xmlElement.getElementsByTagName(attrib)[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
|
44 if (typeof elem != 'undefined' && elem !== 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
|
45 this[attrib] = Strophe.getText(elem); |
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 if (attrib == 'first') { |
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 this.index = elem.getAttribute('index'); |
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 } |
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 } |
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 } |
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 }; |