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;
Object.assign({ try {
'groupchat': is_groupchat, result = await _converse.api.archive.query(
'before': '', // Page backwards from the most recent message Object.assign({
'max': _converse.archived_messages_page_size, 'groupchat': is_groupchat,
'with': this.model.get('jid'), 'before': '', // Page backwards from the most recent message
}, options), 'max': _converse.archived_messages_page_size,
'with': this.model.get('jid'),
messages => { // Success }, options));
this.clearSpinner(); } catch (e) {
_.each(messages, message_handler); _converse.log(
}, "Error or timeout while trying to fetch "+
e => { // Error "archived messages", Strophe.LogLevel.ERROR);
this.clearSpinner(); _converse.log(e, Strophe.LogLevel.ERROR);
_converse.log( } finally {
"Error or timeout while trying to fetch "+ this.clearSpinner();
"archived messages", Strophe.LogLevel.ERROR); }
_converse.log(e, Strophe.LogLevel.ERROR); 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