Initial work on sending a different stanza for OMEMO messages

updates #497
This commit is contained in:
JC Brand 2018-05-15 17:27:07 +02:00
parent a99e7a317e
commit f906761dc0
3 changed files with 49 additions and 4 deletions

View File

@ -170,6 +170,15 @@
const toggle = toolbar.querySelector('.toggle-omemo');
expect(u.hasClass('fa-unlock', toggle)).toBe(false);
expect(u.hasClass('fa-lock', toggle)).toBe(true);
const textarea = view.el.querySelector('.chat-textarea');
textarea.value = 'This message will be sent encrypted';
view.keyPressed({
target: textarea,
preventDefault: _.noop,
keyCode: 13
});
done();
}).catch(_.partial(console.error, _));
}));

View File

@ -308,8 +308,8 @@
},
sendMessageStanza (message) {
const messageStanza = this.createMessageStanza(message);
_converse.connection.send(messageStanza);
const stanza = this.createMessageStanza(message);
_converse.connection.send(stanza);
if (_converse.forward_messages) {
// Forward the message, so that other connected resources are also aware of it.
_converse.connection.send(
@ -322,7 +322,7 @@
'xmns': Strophe.NS.DELAY,
'stamp': moment().format()
}).up()
.cnode(messageStanza.tree())
.cnode(stanza.tree())
);
}
},

View File

@ -13,7 +13,7 @@
], factory);
}(this, function (converse, tpl_toolbar_omemo) {
const { Backbone, Promise, Strophe, sizzle, $iq, _, b64_sha1 } = converse.env;
const { Backbone, Promise, Strophe, sizzle, $iq, $msg, _, b64_sha1 } = converse.env;
const u = converse.env.utils;
Strophe.addNamespace('OMEMO', "eu.siacs.conversations.axolotl");
@ -59,6 +59,42 @@
dependencies: ["converse-chatview"],
overrides: {
ChatBox: {
createOMEMOMessageStanza (message) {
const { _converse } = this.__super__;
const stanza = $msg({
'from': _converse.connection.jid,
'to': this.get('jid'),
'type': this.get('message_type'),
'id': message.get('msgid')
}).c('body').t(message.get('message')).up()
.c(_converse.ACTIVE, {'xmlns': Strophe.NS.CHATSTATES}).up();
if (message.get('is_spoiler')) {
if (message.get('spoiler_hint')) {
stanza.c('spoiler', {'xmlns': Strophe.NS.SPOILER }, message.get('spoiler_hint')).up();
} else {
stanza.c('spoiler', {'xmlns': Strophe.NS.SPOILER }).up();
}
}
if (message.get('file')) {
stanza.c('x', {'xmlns': Strophe.NS.OUTOFBAND}).c('url').t(message.get('message')).up();
}
return stanza;
},
createMessageStanza () {
if (this.get('omemo_active')) {
return this.createOMEMOMessageStanza.apply(this, arguments);
} else {
return this.__super__.createMessageStanza.apply(this, arguments);
}
}
},
ChatBoxView: {
events: {
'click .toggle-omemo': 'toggleOMEMO'