Pārlūkot izejas kodu

Use Strophe.RSM for result set management.

JC Brand 10 gadi atpakaļ
vecāks
revīzija
1261a2525d
7 mainītis faili ar 27 papildinājumiem un 18 dzēšanām
  1. 11 6
      converse.js
  2. 6 6
      main.js
  3. 2 2
      spec/mam.js
  4. 2 1
      src/deps-full.js
  5. 2 1
      src/deps-no-otr.js
  6. 2 1
      src/deps-website-no-otr.js
  7. 2 1
      src/deps-website.js

+ 11 - 6
converse.js

@@ -118,6 +118,11 @@
         }
     };
 
+    // Global constants
+
+    // XEP-0059 Result Set Management
+    var RSM_ATTRIBUTES = ['max', 'first', 'last', 'after', 'before', 'index', 'count'];
+
     var STATUS_WEIGHTS = {
         'offline':      6,
         'unavailable':  5,
@@ -6138,14 +6143,14 @@
                         }
                     });
                     stanza.up();
-                    if (options.limit) {
-                        stanza.c('set', {'xmlns':Strophe.NS.RSM}).c('max').t(options.limit).up();
-                    }
-                    if (options.after) {
-                        stanza.c('after').t(options.after).up();
+                    if (_.intersection(RSM_ATTRIBUTES, _.keys(options)).length) {
+                        stanza.cnode(new Strophe.RSM(options).toXML());
                     }
                 }
-                converse.connection.sendIQ(stanza, callback, errback);
+                converse.connection.sendIQ(stanza, function (iq) {
+                    var rsm = new Strophe.RSM({xml: iq.getElementsByTagName('set')[0]});
+                    return _.bind(callback, this, arguments)(rsm);
+                }, errback);
             }
         },
         'rooms': {

+ 6 - 6
main.js

@@ -27,17 +27,18 @@ require.config({
         "jquery.browser":           "components/jquery.browser/dist/jquery.browser",
         "jquery.easing":            "components/jquery-easing-original/index",          // XXX: Only required for https://conversejs.org website
         "moment":                   "components/momentjs/moment",
+        "strophe":                  "components/strophejs/src/wrapper",
         "strophe-base64":           "components/strophejs/src/base64",
         "strophe-bosh":             "components/strophejs/src/bosh",
         "strophe-core":             "components/strophejs/src/core",
-        "strophe":                  "components/strophejs/src/wrapper",
         "strophe-md5":              "components/strophejs/src/md5",
+        "strophe-polyfill":         "components/strophejs/src/polyfills",
         "strophe-sha1":             "components/strophejs/src/sha1",
         "strophe-websocket":        "components/strophejs/src/websocket",
-        "strophe-polyfill":         "components/strophejs/src/polyfills",
         "strophe.disco":            "components/strophejs-plugins/disco/strophe.disco",
-        "strophe.vcard":            "src/strophe.vcard",
         "strophe.ping":             "src/strophe.ping",
+        "strophe.rsm":              "components/strophejs-plugins/rsm/strophe.rsm",
+        "strophe.vcard":            "src/strophe.vcard",
         "text":                     'components/requirejs-text/text',
         "tpl":                      'components/requirejs-tpl-jcbrand/tpl',
         "typeahead":                "components/typeahead.js/index",
@@ -185,10 +186,9 @@ require.config({
         'crypto.sha1':          { deps: ['crypto.core'] },
         'crypto.sha256':        { deps: ['crypto.core'] },
         'bigint':               { deps: ['crypto'] },
-        'strophe.disco':        { deps: ['strophe'] },
+        'strophe.ping':         { deps: ['strophe'] },
         'strophe.register':     { deps: ['strophe'] },
-        'strophe.vcard':        { deps: ['strophe'] },
-        'strophe.ping':         { deps: ['strophe'] }
+        'strophe.vcard':        { deps: ['strophe'] }
     }
 });
 

+ 2 - 2
spec/mam.js

@@ -161,7 +161,7 @@
                 Date.prototype.getTimezoneOffset = function () {
                     return -120;
                 };
-                converse_api.archive.query({'start': '2010-06-07T00:00:00Z', 'limit':10});
+                converse_api.archive.query({'start': '2010-06-07T00:00:00Z', 'max':10});
                 var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
                 expect(sent_stanza.toString()).toBe(
                     "<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
@@ -202,7 +202,7 @@
                 converse_api.archive.query({
                     'start': '2010-06-07T00:00:00Z',
                     'after': '09af3-cc343-b409f',
-                    'limit':10
+                    'max':10
                 });
                 var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
                 expect(sent_stanza.toString()).toBe(

+ 2 - 1
src/deps-full.js

@@ -4,9 +4,10 @@ define("converse-dependencies", [
     "otr",
     "moment_with_locales",
     "strophe",
-    "strophe.vcard",
     "strophe.disco",
     "strophe.ping",
+    "strophe.rsm",
+    "strophe.vcard",
     "backbone.browserStorage",
     "backbone.overview",
     "jquery.browser",

+ 2 - 1
src/deps-no-otr.js

@@ -3,9 +3,10 @@ define("converse-dependencies", [
     "utils",
     "moment_with_locales",
     "strophe",
-    "strophe.vcard",
     "strophe.disco",
     "strophe.ping",
+    "strophe.rsm",
+    "strophe.vcard",
     "backbone.browserStorage",
     "backbone.overview",
     "jquery.browser",

+ 2 - 1
src/deps-website-no-otr.js

@@ -3,9 +3,10 @@ define("converse-dependencies", [
     "utils",
     "moment_with_locales",
     "strophe",
-    "strophe.vcard",
     "strophe.disco",
     "strophe.ping",
+    "strophe.rsm",
+    "strophe.vcard",
     "bootstrapJS", // XXX: Can be removed, only for https://conversejs.org
     "backbone.browserStorage",
     "backbone.overview",

+ 2 - 1
src/deps-website.js

@@ -5,9 +5,10 @@ define("converse-dependencies", [
     "otr",
     "moment_with_locales",
     "strophe",
-    "strophe.vcard",
     "strophe.disco",
     "strophe.ping",
+    "strophe.rsm",
+    "strophe.vcard",
     "bootstrapJS", // XXX: Only for https://conversejs.org
     "backbone.browserStorage",
     "backbone.overview",