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.
This commit is contained in:
JC Brand 2018-07-01 11:45:34 +02:00
parent 6785eff4a7
commit 648c0387dd
2 changed files with 16 additions and 36 deletions

View File

@ -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 () {

View File

@ -141,9 +141,9 @@
},
createOMEMOMessageStanza (message, bundles) {
const { _converse } = this.__super__;
const body = "This is an OMEMO encrypted message which your client doesnt 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 doesnt 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,37 +165,17 @@
});
},
createMessageStanza (message) {
if (this.get('omemo_active')) {
return this.getBundlesAndBuildSessions()
.then((bundles) => this.createOMEMOMessageStanza(message, bundles));
} else {
return Promise.resolve(this.__super__.createMessageStanza.apply(this, arguments));
}
},
sendMessageStanza (message) {
sendMessage (attrs) {
const { _converse } = this.__super__;
const message = this.messages.create(attrs);
// 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));
if (this.get('omemo_active')) {
this.getBundlesAndBuildSessions()
.then((bundles) => this.createOMEMOMessageStanza(message, bundles))
.then((stanza) => this.sendMessageStanza(stanza));
} else {
this.sendMessageStanza(this.createMessageStanza(message));
}
},
},