Преглед изворни кода

Show most recent archived messages first.

- Also ensure that the archive.query API always return messages chronologically.
- Fix docs which wrongly state that null can be passed in.

updates #306
JC Brand пре 10 година
родитељ
комит
080d86e7fe
2 измењених фајлова са 4 додато и 2 уклоњено
  1. 2 0
      converse.js
  2. 2 2
      docs/source/development.rst

+ 2 - 0
converse.js

@@ -564,6 +564,7 @@
                         $fin = $msg.find('fin[xmlns="'+Strophe.NS.MAM+'"]');
                         $fin = $msg.find('fin[xmlns="'+Strophe.NS.MAM+'"]');
                         if ($fin.length) {
                         if ($fin.length) {
                             rsm = new Strophe.RSM({xml: $fin.find('set')[0]});
                             rsm = new Strophe.RSM({xml: $fin.find('set')[0]});
+                            if (typeof options.before !== "undefined") { messages.reverse(); }
                             _.extend(rsm, _.pick(options, ['max', 'after', 'before']));
                             _.extend(rsm, _.pick(options, ['max', 'after', 'before']));
                             _.extend(rsm, _.pick(options, MAM_ATTRIBUTES));
                             _.extend(rsm, _.pick(options, MAM_ATTRIBUTES));
                             callback(messages, rsm);
                             callback(messages, rsm);
@@ -1331,6 +1332,7 @@
 
 
                     // TODO: fetch only messages we don't yet have
                     // TODO: fetch only messages we don't yet have
                     API.archive.query({
                     API.archive.query({
+                            'before': '', // Page backwards from the most recent message
                             'with': this.model.get('jid'),
                             'with': this.model.get('jid'),
                             'max': converse.archived_messages_batch_size
                             'max': converse.archived_messages_batch_size
                         },
                         },

+ 2 - 2
docs/source/development.rst

@@ -319,11 +319,11 @@ archived messages.
 To page backwards through the archive, you need to know the UID of the message
 To page backwards through the archive, you need to know the UID of the message
 which you'd like to page backwards from and then pass that as value for the
 which you'd like to page backwards from and then pass that as value for the
 ``before`` parameter. If you simply want to page backwards from the most recent
 ``before`` parameter. If you simply want to page backwards from the most recent
-message, pass in the ``before`` parameter with a value of ``null``.
+message, pass in the ``before`` parameter with an empty string value ``''``.
 
 
 .. code-block:: javascript
 .. code-block:: javascript
 
 
-    converse.archive.query({'before': null, 'max':5}, function (message, rsm) {
+    converse.archive.query({'before': '', 'max':5}, function (message, rsm) {
         // Do something with the messages, like showing them in your webpage.
         // Do something with the messages, like showing them in your webpage.
         // ...
         // ...
         // You can now use the returned "rsm" object, to fetch the previous batch of messages:
         // You can now use the returned "rsm" object, to fetch the previous batch of messages: