Commit 15b22736 authored by JC Brand's avatar JC Brand

`_converse.api.archive.query` now returns a Promise

instead of accepting a callback functions.
parent 8bb852b1
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
- **Breaking changes**: - **Breaking changes**:
- Rename `muc_disable_moderator_commands` to [muc_disable_slash_commands](https://conversejs.org/docs/html/configuration.html#muc-disable-slash-commands). - Rename `muc_disable_moderator_commands` to [muc_disable_slash_commands](https://conversejs.org/docs/html/configuration.html#muc-disable-slash-commands).
- `_converse.api.archive.query` now returns a Promise instead of accepting a callback functions.
### API changes ### API changes
......
This diff is collapsed.
This diff is collapsed.
...@@ -82,10 +82,10 @@ converse.plugins.add('converse-mam-views', { ...@@ -82,10 +82,10 @@ converse.plugins.add('converse-mam-views', {
async fetchArchivedMessages (options) { async fetchArchivedMessages (options) {
const { _converse } = this.__super__; const { _converse } = this.__super__;
if (this.disable_mam) { return; } if (this.disable_mam) {
return;
}
const is_groupchat = this.model.get('type') === CHATROOMS_TYPE; const is_groupchat = this.model.get('type') === CHATROOMS_TYPE;
let mam_jid, message_handler; let mam_jid, message_handler;
if (is_groupchat) { if (is_groupchat) {
mam_jid = this.model.get('jid'); mam_jid = this.model.get('jid');
...@@ -94,32 +94,31 @@ converse.plugins.add('converse-mam-views', { ...@@ -94,32 +94,31 @@ converse.plugins.add('converse-mam-views', {
mam_jid = _converse.bare_jid; mam_jid = _converse.bare_jid;
message_handler = _converse.chatboxes.onMessage.bind(_converse.chatboxes) message_handler = _converse.chatboxes.onMessage.bind(_converse.chatboxes)
} }
const supported = await _converse.api.disco.supports(Strophe.NS.MAM, mam_jid); const supported = await _converse.api.disco.supports(Strophe.NS.MAM, mam_jid);
if (!supported.length) { if (!supported.length) {
return; return;
} }
this.addSpinner(); this.addSpinner();
_converse.api.archive.query( let result;
try {
result = await _converse.api.archive.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.model.get('jid'), 'with': this.model.get('jid'),
}, options), }, options));
} catch (e) {
messages => { // Success
this.clearSpinner();
_.each(messages, message_handler);
},
e => { // Error
this.clearSpinner();
_converse.log( _converse.log(
"Error or timeout while trying to fetch "+ "Error or timeout while trying to fetch "+
"archived messages", Strophe.LogLevel.ERROR); "archived messages", Strophe.LogLevel.ERROR);
_converse.log(e, Strophe.LogLevel.ERROR); _converse.log(e, Strophe.LogLevel.ERROR);
} finally {
this.clearSpinner();
}
if (result.messages) {
result.messages.forEach(message_handler);
} }
);
}, },
onScroll (ev) { onScroll (ev) {
......
This diff is collapsed.
This diff is collapsed.
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