소스 검색

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+'"]');
                         if ($fin.length) {
                             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, MAM_ATTRIBUTES));
                             callback(messages, rsm);
@@ -1331,6 +1332,7 @@
 
                     // TODO: fetch only messages we don't yet have
                     API.archive.query({
+                            'before': '', // Page backwards from the most recent message
                             'with': this.model.get('jid'),
                             '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
 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
-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
 
-    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.
         // ...
         // You can now use the returned "rsm" object, to fetch the previous batch of messages: