changeset 529:9bfd71e2b35c

plugin OTR: disconnect the active OTR sessions on profile disconnection
author souliane <souliane@mailoo.org>
date Fri, 05 Sep 2014 11:41:40 +0200
parents ac66b8b11ab8
children 1735aaeac652
files src/browser/sat_browser/menu.py src/browser/sat_browser/plugin_sec_otr.py
diffstat 2 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser/sat_browser/menu.py	Fri Sep 05 10:47:17 2014 +0200
+++ b/src/browser/sat_browser/menu.py	Fri Sep 05 11:41:40 2014 +0200
@@ -104,6 +104,11 @@
     def onDisconnect(self):
         def confirm_cb(answer):
             if answer:
+                # FIXME: are we sure the triggers finished their jobs when the backend disconnect?
+                # FIXME: disconnection on timeout is not handled yet...
+                for plugin in self.plugins.values():
+                    if hasattr(plugin, 'profileConnected'):
+                        plugin.profileDisconnected()
                 log.info("disconnection")
                 self.host.bridge.call('disconnect', None)
         _dialog = dialog.ConfirmDialog(confirm_cb, text="Do you really want to disconnect ?")
--- a/src/browser/sat_browser/plugin_sec_otr.py	Fri Sep 05 10:47:17 2014 +0200
+++ b/src/browser/sat_browser/plugin_sec_otr.py	Fri Sep 05 11:41:40 2014 +0200
@@ -220,6 +220,11 @@
         elif type_ == 'abort':
             self.setCurrentTrust('', act, 'abort')
 
+    def disconnect(self):
+        """Disconnect the session."""
+        if self.state != otr.context.STATE_PLAINTEXT:
+            super(Context, self).disconnect()
+
 
 class Account(otr.context.Account):
 
@@ -298,6 +303,10 @@
         # decrypt it, parse it with otr.crypt.PK.parsePrivateKey(privkey) and
         # assign it to self.context_manager.account.privkey
 
+    def profileDisconnected(self):
+        for context in self.context_manager.contexts.values():
+            context.disconnect()
+
     def fixResource(self, jid, cb):
         # FIXME: it's dirty, but libervia doesn't manage resources correctly now, refactoring is planed
         if jid.resource:
@@ -437,8 +446,7 @@
                 if confirm:
                     # we end all sessions
                     for context in self.context_manager.contexts.values():
-                        if context.state not in (otr.context.STATE_FINISHED, otr.context.STATE_PLAINTEXT):
-                            context.disconnect()
+                        context.disconnect()
                     self.context_manager.account.privkey = None
                     self.context_manager.account.getPrivkey()  # as account.privkey are None, getPrivkey will generate a new key, and save it
                     dialog.InfoDialog(_('Private key'), _("Your private key has been dropped."), AddStyleName="maxWidthLimit").show()