Commit 080d86e7 authored by JC Brand's avatar JC Brand

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
parent 8625d1da
......@@ -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
},
......
......@@ -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:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment