diff src/plugins/plugin_sec_otr.py @ 1168:39572f9d5249

plugin OTR: fixes handling of the FINISHED state
author souliane <souliane@mailoo.org>
date Fri, 05 Sep 2014 10:39:06 +0200
parents 652cd93dfdb4
children a3354063dfb6
line wrap: on
line diff
--- a/src/plugins/plugin_sec_otr.py	Thu Sep 04 11:26:22 2014 +0200
+++ b/src/plugins/plugin_sec_otr.py	Fri Sep 05 10:39:06 2014 +0200
@@ -427,11 +427,21 @@
         if mess_data['type'] != 'groupchat' and not to_jid.resource:
             to_jid.resource = self.host.memory.getLastResource(to_jid, profile) # FIXME: it's dirty, but frontends don't manage resources correctly now, refactoring is planed
         otrctx = self.context_managers[profile].getContextForUser(to_jid)
-        if mess_data['type'] != 'groupchat' and otrctx.state == potr.context.STATE_ENCRYPTED:
-            log.debug(u"encrypting message")
-            otrctx.sendMessage(0, mess_data['message'].encode('utf-8'))
-            client = self.host.getClient(profile)
-            self.host.sendMessageToBridge(mess_data, client)
+        if mess_data['type'] != 'groupchat' and otrctx.state != potr.context.STATE_PLAINTEXT:
+            if otrctx.state == potr.context.STATE_ENCRYPTED:
+                log.debug(u"encrypting message")
+                otrctx.sendMessage(0, mess_data['message'].encode('utf-8'))
+                client = self.host.getClient(profile)
+                self.host.sendMessageToBridge(mess_data, client)
+            else:
+                feedback = D_("Your message was not sent because your correspondent closed the encrypted conversation on his/her side. Either close your own side, or refresh the session.")
+                client = self.host.getClient(profile)
+                self.host.bridge.newMessage(to_jid.full(),
+                                            feedback,
+                                            mess_type="headline",
+                                            to_jid=client.jid.full(),
+                                            extra={},
+                                            profile=client.profile)
             return False
         else:
             log.debug(u"sending message unencrypted")