Commit 8a9a0a4b authored by JC Brand's avatar JC Brand

Add support for paging through MAM results when catching up

Fixes #1548
parent c7b6bb47
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
- #1524: OMEMO libsignal-protocol.js Invalid signature - #1524: OMEMO libsignal-protocol.js Invalid signature
- #1532: Converse reloads on enter pressed in the filter box - #1532: Converse reloads on enter pressed in the filter box
- #1538: Allow adding self as contact - #1538: Allow adding self as contact
- #1548: Add support for paging through the MAM results when filling in the blanks
- #1550: Legitimate carbons being blocked due to erroneous forgery check - #1550: Legitimate carbons being blocked due to erroneous forgery check
- #1554: Room auto-configuration broke if the config form contained fields with type `fixed` - #1554: Room auto-configuration broke if the config form contained fields with type `fixed`
- #1558: `this.get` is not a function error when `forward_messages` is set to `true`. - #1558: `this.get` is not a function error when `forward_messages` is set to `true`.
......
This diff is collapsed.
...@@ -102,14 +102,25 @@ converse.plugins.add('converse-mam', { ...@@ -102,14 +102,25 @@ converse.plugins.add('converse-mam', {
} else { } else {
message_handler = _converse.chatboxes.onMessage.bind(_converse.chatboxes) message_handler = _converse.chatboxes.onMessage.bind(_converse.chatboxes)
} }
const result = await _converse.api.archive.query( const query = Object.assign({
Object.assign({
'groupchat': is_groupchat, 'groupchat': is_groupchat,
'before': '', // Page backwards from the most recent message 'before': '', // Page backwards from the most recent message
'max': _converse.archived_messages_page_size, 'max': _converse.archived_messages_page_size,
'with': this.get('jid'), 'with': this.get('jid'),
}, options)); }, options);
const result = await _converse.api.archive.query(query);
result.messages.forEach(message_handler); result.messages.forEach(message_handler);
const catching_up = query.before || query.after;
if (result.rsm) {
if (catching_up) {
return this.fetchArchivedMessages(result.rsm.previous(_converse.archived_messages_page_size));
} else {
// TODO: Add a special kind of message which will
// render as a link to fetch further messages, either
// to fetch older messages or to fill in a gap.
}
}
}, },
async findDuplicateFromArchiveID (stanza) { async findDuplicateFromArchiveID (stanza) {
...@@ -455,7 +466,7 @@ converse.plugins.add('converse-mam', { ...@@ -455,7 +466,7 @@ converse.plugins.add('converse-mam', {
stanza.up(); stanza.up();
if (options instanceof _converse.RSM) { if (options instanceof _converse.RSM) {
stanza.cnode(options.toXML()); stanza.cnode(options.toXML());
} else if (_.intersection(_converse.RSM_ATTRIBUTES, Object.keys(options)).length) { } else if (intersection(_converse.RSM_ATTRIBUTES, Object.keys(options)).length) {
stanza.cnode(new _converse.RSM(options).toXML()); stanza.cnode(new _converse.RSM(options).toXML());
} }
} }
...@@ -483,10 +494,13 @@ converse.plugins.add('converse-mam', { ...@@ -483,10 +494,13 @@ converse.plugins.add('converse-mam', {
} }
_converse.connection.deleteHandler(message_handler); _converse.connection.deleteHandler(message_handler);
const set = iq_result ? iq_result.querySelector('set') : null; const fin = iq_result && sizzle(`fin[xmlns="${Strophe.NS.MAM}"]`, iq_result).pop();
if (set !== null) { if (fin && [null, 'false'].includes(fin.getAttribute('complete'))) {
rsm = new _converse.RSM({'xml': set}); const set = sizzle(`set[xmlns="${Strophe.NS.RSM}"]`, fin).pop();
Object.assign(rsm, _.pick(options, _.concat(MAM_ATTRIBUTES, ['max']))); if (set) {
rsm = new _converse.RSM({'xml': set});
Object.assign(rsm, pick(options, [...MAM_ATTRIBUTES, ..._converse.RSM_ATTRIBUTES]));
}
} }
return { messages, rsm } return { messages, rsm }
} }
......
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