Prechádzať zdrojové kódy

Initial work on sending a different stanza for OMEMO messages

updates #497
JC Brand 7 rokov pred
rodič
commit
f906761dc0
3 zmenil súbory, kde vykonal 49 pridanie a 4 odobranie
  1. 9 0
      spec/omemo.js
  2. 3 3
      src/converse-chatboxes.js
  3. 37 1
      src/converse-omemo.js

+ 9 - 0
spec/omemo.js

@@ -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, _));
         }));

+ 3 - 3
src/converse-chatboxes.js

@@ -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())
                         );
                     }
                 },

+ 37 - 1
src/converse-omemo.js

@@ -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'