Commit 648c0387 authored by JC Brand's avatar JC Brand

Refactor message sending

so that we don't have to always wait for stanza creation.
We only need to wait when OMEMO is active, so we keep the waiting
contained to that usecase.
parent 6785eff4
......@@ -264,7 +264,7 @@
this.messages.on('change:upload', (message) => {
if (message.get('upload') === _converse.SUCCESS) {
this.sendMessageStanza(message);
this.sendMessageStanza(this.createMessageStanza(message));
}
});
......@@ -318,8 +318,7 @@
return stanza;
},
sendMessageStanza (message) {
const stanza = this.createMessageStanza(message);
sendMessageStanza (stanza) {
_converse.connection.send(stanza);
if (_converse.forward_messages) {
// Forward the message, so that other connected resources are also aware of it.
......@@ -358,7 +357,8 @@
* Parameters:
* (Message) message - The chat message
*/
this.sendMessageStanza(this.messages.create(attrs));
const message = this.messages.create(attrs);
this.sendMessageStanza(this.createMessageStanza(message));
},
sendChatState () {
......
......@@ -141,9 +141,9 @@
},
createOMEMOMessageStanza (message, bundles) {
const { _converse } = this.__super__;
const body = "This is an OMEMO encrypted message which your client doesn’t seem to support. "+
"Find more information on https://conversations.im/omemo";
const { _converse } = this.__super__, { __ } = _converse;
const body = __("This is an OMEMO encrypted message which your client doesn’t seem to support. "+
"Find more information on https://conversations.im/omemo");
return new Promise((resolve, reject) => {
this.encryptMessage(message).then((payload) => {
const stanza = $msg({
......@@ -165,38 +165,18 @@
});
},
createMessageStanza (message) {
sendMessage (attrs) {
const { _converse } = this.__super__;
const message = this.messages.create(attrs);
if (this.get('omemo_active')) {
return this.getBundlesAndBuildSessions()
.then((bundles) => this.createOMEMOMessageStanza(message, bundles));
this.getBundlesAndBuildSessions()
.then((bundles) => this.createOMEMOMessageStanza(message, bundles))
.then((stanza) => this.sendMessageStanza(stanza));
} else {
return Promise.resolve(this.__super__.createMessageStanza.apply(this, arguments));
this.sendMessageStanza(this.createMessageStanza(message));
}
},
sendMessageStanza (message) {
const { _converse } = this.__super__;
// TODO: merge this back into converse-chatboxes
this.createMessageStanza(message).then((stanza) => {
_converse.connection.send(stanza);
if (_converse.forward_messages) {
// Forward the message, so that other connected resources are also aware of it.
_converse.connection.send(
$msg({
'to': _converse.bare_jid,
'type': this.get('message_type'),
'id': message.get('msgid')
}).c('forwarded', {'xmlns': Strophe.NS.FORWARD})
.c('delay', {
'xmns': Strophe.NS.DELAY,
'stamp': moment().format()
}).up()
.cnode(stanza.tree())
);
}
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
},
},
ChatBoxView: {
......
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