Commit 79bfb456 authored by JC Brand's avatar JC Brand

Use async/await in MAM code and tests

parent 6e05f3b6
This diff is collapsed.
......@@ -331,10 +331,10 @@ converse.plugins.add('converse-omemo', {
}
},
getMessageAttributesFromStanza (stanza, original_stanza) {
async getMessageAttributesFromStanza (stanza, original_stanza) {
const { _converse } = this.__super__,
encrypted = sizzle(`encrypted[xmlns="${Strophe.NS.OMEMO}"]`, original_stanza).pop(),
attrs = this.__super__.getMessageAttributesFromStanza.apply(this, arguments);
attrs = await this.__super__.getMessageAttributesFromStanza.apply(this, arguments);
if (!encrypted || !_converse.config.get('trusted')) {
return attrs;
......
......@@ -557,31 +557,22 @@ converse.plugins.add('converse-chatboxes', {
return attrs;
},
createMessage (message, original_stanza) {
async createMessage (message, original_stanza) {
/* Create a Backbone.Message object inside this chat box
* based on the identified message stanza.
*/
const that = this;
function _create (attrs) {
const is_csn = u.isOnlyChatStateNotification(attrs);
if (is_csn && (attrs.is_delayed ||
(attrs.type === 'groupchat' && Strophe.getResourceFromJid(attrs.from) == that.get('nick')))) {
// XXX: MUC leakage
// No need showing delayed or our own CSN messages
return;
} else if (!is_csn && !attrs.file && !attrs.plaintext && !attrs.message && !attrs.oob_url && attrs.type !== 'error') {
// TODO: handle <subject> messages (currently being done by ChatRoom)
return;
} else {
return that.messages.create(attrs);
}
}
const result = this.getMessageAttributesFromStanza(message, original_stanza)
if (typeof result.then === "function") {
return new Promise((resolve, reject) => result.then(attrs => resolve(_create(attrs))));
const attrs = await this.getMessageAttributesFromStanza(message, original_stanza),
is_csn = u.isOnlyChatStateNotification(attrs);
if (is_csn && (attrs.is_delayed || (attrs.type === 'groupchat' && Strophe.getResourceFromJid(attrs.from) == this.get('nick')))) {
// XXX: MUC leakage
// No need showing delayed or our own CSN messages
return;
} else if (!is_csn && !attrs.file && !attrs.plaintext && !attrs.message && !attrs.oob_url && attrs.type !== 'error') {
// TODO: handle <subject> messages (currently being done by ChatRoom)
return;
} else {
const message = _create(result)
return Promise.resolve(message);
return this.messages.create(attrs);
}
},
......
......@@ -133,20 +133,10 @@ converse.plugins.add('converse-mam', {
// New functions which don't exist yet can also be added.
ChatBox: {
getMessageAttributesFromStanza (message, original_stanza) {
function _process (attrs) {
const archive_id = getMessageArchiveID(original_stanza);
if (archive_id) {
attrs.archive_id = archive_id;
}
return attrs;
}
const result = this.__super__.getMessageAttributesFromStanza.apply(this, arguments)
if (result instanceof Promise) {
return new Promise((resolve, reject) => result.then((attrs) => resolve(_process(attrs))).catch(reject));
} else {
return _process(result);
}
async getMessageAttributesFromStanza (message, original_stanza) {
const attrs = await this.__super__.getMessageAttributesFromStanza.apply(this, arguments);
attrs.archive_id = getMessageArchiveID(original_stanza);
return attrs;
}
},
......
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