diff src/browser/sat_browser/plugin_sec_otr.py @ 914:0c0551967bdf

server, browser: partial Libervia fix Libervia was broken following the refactorings. This commit partially fixes it : Libervia is starting, avatar, blog and message are working again, but not everything is restablished yet. following things have been fixed/changed: - new dependency: shortuuid - D-Bus bridge is working again - fixed naming in several bridge methods - register method changed to register_signal - fixed Chat widget, which was not working anymore since the refactoring - avatar now use avatarGet. Cache dir is accessible using a session specific uuid, to avoid cache leak (i.e. accessing cache of other profiles) - server: new uuid attribute in session data Browser code is not fully working yet, notably OTR and contact list are not fully fixed.
author Goffi <goffi@goffi.org>
date Sun, 26 Feb 2017 18:32:47 +0100
parents e8b133b77aa4
children fd4eae654182
line wrap: on
line diff
--- a/src/browser/sat_browser/plugin_sec_otr.py	Sun Aug 28 19:25:52 2016 +0200
+++ b/src/browser/sat_browser/plugin_sec_otr.py	Sun Feb 26 18:32:47 2017 +0100
@@ -35,6 +35,8 @@
 import otrjs_wrapper as otr
 import dialog
 import chat
+import uuid
+import time
 
 
 NS_OTR = "otr_plugin"
@@ -162,11 +164,12 @@
         if not encrypted:
             log.warning(u"A plain-text message has been handled by otr.js")
         log.debug(u"message received (was %s): %s" % ('encrypted' if encrypted else 'plain', msg))
+        uuid_ = str(uuid.uuid4())  # FIXME
         if not encrypted:
             if self.state == otr.context.STATE_ENCRYPTED:
                 log.warning(u"Received unencrypted message in an encrypted context (from %(jid)s)" % {'jid': self.peer})
-                self.host.newMessageHandler(unicode(self.peer), RECEIVE_PLAIN_IN_ENCRYPTED_CONTEXT, C.MESS_TYPE_INFO, unicode(self.host.whoami), {})
-        self.host.newMessageHandler(unicode(self.peer), msg, C.MESS_TYPE_CHAT, unicode(self.host.whoami), {})
+                self.host.newMessageHandler(uuid_, time.time(), unicode(self.peer), unicode(self.host.whoami), {'': RECEIVE_PLAIN_IN_ENCRYPTED_CONTEXT}, {}, C.MESS_TYPE_INFO, {})
+        self.host.newMessageHandler(uuid_, time.time(), unicode(self.peer), unicode(self.host.whoami), {'': msg}, {}, C.MESS_TYPE_CHAT, {})
 
     def sendMessageCb(self, msg, meta=None):
         assert isinstance(self.peer, jid.JID)
@@ -199,7 +202,8 @@
             elif msg_state == otr.context.STATE_FINISHED:
                 feedback = END_FINISHED
 
-        self.host.newMessageHandler(unicode(self.peer), feedback.format(jid=other_jid_s), C.MESS_TYPE_INFO, unicode(self.host.whoami), {'header_info': OTR.getInfoText(msg_state, trust)})
+        uuid_ = str(uuid.uuid4())  # FIXME
+        self.host.newMessageHandler(uuid_, time.time(), unicode(self.peer), unicode(self.host.whoami), {'': feedback.format(jid=other_jid_s)}, {}, C.MESS_TYPE_INFO, {'header_info': OTR.getInfoText(msg_state, trust)})
 
     def setCurrentTrust(self, new_trust='', act='asked', type_='trust'):
         log.debug(u"setCurrentTrust: trust={trust}, act={act}, type={type}".format(type=type_, trust=new_trust, act=act))
@@ -222,7 +226,8 @@
         otr.context.Context.setCurrentTrust(self, new_trust)
         if old_trust != new_trust:
             feedback = AUTH_STATUS.format(state=(AUTH_TRUSTED if new_trust else AUTH_UNTRUSTED).lower())
-            self.host.newMessageHandler(unicode(self.peer), feedback, C.MESS_TYPE_INFO, unicode(self.host.whoami), {'header_info': OTR.getInfoText(self.state, new_trust)})
+            uuid_ = str(uuid.uuid4())  # FIXME
+            self.host.newMessageHandler(uuid_, time.time(), unicode(self.peer), unicode(self.host.whoami), {'': feedback}, {}, C.MESS_TYPE_INFO, {'header_info': OTR.getInfoText(self.state, new_trust)})
 
     def fingerprintAuthCb(self):
         """OTR v2 authentication using manual fingerprint comparison"""
@@ -388,8 +393,8 @@
         self.host = host
         self.context_manager = None
         self.host.bridge._registerMethods(["skipOTR"])
-        self.host.trigger.add("messageNewTrigger", self.newMessageTg, priority=trigger.TriggerManager.MAX_PRIORITY) # FIXME: need to be fixed after message refactoring
-        self.host.trigger.add("sendMessageTrigger", self.sendMessageTg, priority=trigger.TriggerManager.MAX_PRIORITY)
+        self.host.trigger.add("messageNewTrigger", self.newMessageTg, priority=trigger.TriggerManager.MAX_PRIORITY)
+        self.host.trigger.add("messageSendTrigger", self.sendMessageTg, priority=trigger.TriggerManager.MAX_PRIORITY)
 
         # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword)
         self._profilePluggedListener = self.profilePluggedListener
@@ -453,10 +458,14 @@
         if show == C.PRESENCE_UNAVAILABLE:
             self.endSession(entity, disconnect=False)
 
-    def newMessageTg(self, from_jid, msg, msg_type, to_jid, extra, profile):
+    def newMessageTg(self, uid, timestamp, from_jid, to_jid, msg, subject, msg_type, extra, profile):
         if msg_type != C.MESS_TYPE_CHAT:
             return True
 
+        try:
+            msg = msg.values()[0]  # FIXME: Q&D fix for message refactoring, message is now a dict
+        except IndexError:
+            return True
         tag = otr.proto.checkForOTR(msg)
         if tag is None or (tag == otr.context.WHITESPACE_TAG and not DEFAULT_POLICY_FLAGS['WHITESPACE_START_AKE']):
             return True
@@ -488,7 +497,8 @@
             if otrctx.state == otr.context.STATE_ENCRYPTED:
                 log.debug(u"encrypting message")
                 otrctx.sendMessage(message)
-                self.host.newMessageHandler(unicode(self.host.whoami), message, mess_type, unicode(to_jid), extra)
+                uuid_ = str(uuid.uuid4())  # FIXME
+                self.host.newMessageHandler(uuid_, time.time(), unicode(self.host.whoami), unicode(to_jid), {'': message}, {}, mess_type,  extra)
             else:
                 feedback = SEND_PLAIN_IN_FINISHED_CONTEXT
                 dialog.InfoDialog(FINISHED_CONTEXT_TITLE.format(jid=to_jid), feedback, AddStyleName="maxWidthLimit").show()
@@ -511,7 +521,8 @@
         for otrctx in contexts:
             if otrctx is None or otrctx.state == otr.context.STATE_PLAINTEXT:
                 if disconnect:
-                    self.host.newMessageHandler(unicode(other_jid), END_PLAIN_HAS_NOT.format(jid=other_jid), C.MESS_TYPE_INFO, unicode(self.host.whoami), {})
+                    uuid_ = str(uuid.uuid4())  # FIXME
+                    self.host.newMessageHandler(uuid_, time.time(), unicode(other_jid), unicode(self.host.whoami), {'': END_PLAIN_HAS_NOT.format(jid=other_jid)}, {}, C.MESS_TYPE_INFO, {})
                 return
             if disconnect:
                 otrctx.disconnect()