Mercurial > libervia-web
comparison src/browser/sat_browser/plugin_sec_otr.py @ 528:ac66b8b11ab8
plugin OTR: fixes handling of the FINISHED state
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 05 Sep 2014 10:47:17 +0200 |
parents | 307f84fee972 |
children | 9bfd71e2b35c |
comparison
equal
deleted
inserted
replaced
527:4c6d7db9b45c | 528:ac66b8b11ab8 |
---|---|
251 def __init__(self, host): | 251 def __init__(self, host): |
252 self.host = host | 252 self.host = host |
253 self.account = Account(host) | 253 self.account = Account(host) |
254 self.contexts = {} | 254 self.contexts = {} |
255 | 255 |
256 def startContext(self, other_jid, create=True): | 256 def startContext(self, other_jid): |
257 assert isinstance(other_jid, jid.JID) | 257 assert isinstance(other_jid, jid.JID) |
258 # FIXME upstream: apparently pyjamas doesn't implement setdefault well, it ignores JID.__hash__ redefinition | 258 # FIXME upstream: apparently pyjamas doesn't implement setdefault well, it ignores JID.__hash__ redefinition |
259 #context = self.contexts.setdefault(other_jid, Context(self.host, self.account, other_jid)) | 259 #context = self.contexts.setdefault(other_jid, Context(self.host, self.account, other_jid)) |
260 if other_jid not in self.contexts: | 260 if other_jid not in self.contexts: |
261 if create: | 261 self.contexts[other_jid] = Context(self.host, self.account, other_jid) |
262 self.contexts[other_jid] = Context(self.host, self.account, other_jid) | |
263 else: | |
264 return None | |
265 return self.contexts[other_jid] | 262 return self.contexts[other_jid] |
266 | 263 |
267 def getContextForUser(self, other, create=True): | 264 def getContextForUser(self, other, create=True): |
268 log.debug(u"getContextForUser [%s]" % other) | 265 log.debug(u"getContextForUser [%s]" % other) |
269 if not other.resource: | 266 if not other.resource: |
270 log.error("getContextForUser called with a bare jid") | 267 log.error("getContextForUser called with a bare jid") |
271 return self.startContext(other, create) | 268 if start: |
269 return self.startContext(other_jid) | |
270 else: | |
271 return self.contexts.get(other_jid, None) | |
272 | 272 |
273 | 273 |
274 class OTR(object): | 274 class OTR(object): |
275 | 275 |
276 def __init__(self, host): | 276 def __init__(self, host): |
321 | 321 |
322 self.fixResource(other_jid, cb) | 322 self.fixResource(other_jid, cb) |
323 | 323 |
324 def sendMessageTrigger(self, to_jid, msg, msg_type, extra): | 324 def sendMessageTrigger(self, to_jid, msg, msg_type, extra): |
325 def cb(jid): | 325 def cb(jid): |
326 otrctx = self.context_manager.getContextForUser(jid) | 326 otrctx = self.context_manager.getContextForUser(jid, start=False) |
327 if msg_type != 'groupchat' and otrctx.state == otr.context.STATE_ENCRYPTED: | 327 if otrctx is not None and msg_type != 'groupchat' and otrctx.state != otr.context.STATE_PLAINTEXT: |
328 log.debug(u"encrypting message") | 328 if otrctx.state == otr.context.STATE_ENCRYPTED: |
329 otrctx.sendMessage(msg) | 329 log.debug(u"encrypting message") |
330 self.host.newMessageCb(self.host.whoami, msg, msg_type, jid, extra) | 330 otrctx.sendMessage(msg) |
331 self.host.newMessageCb(self.host.whoami, msg, msg_type, jid, extra) | |
332 else: | |
333 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.") | |
334 dialog.InfoDialog(_('Finished encrypted session'), feedback, AddStyleName="maxWidthLimit").show() | |
331 else: | 335 else: |
332 log.debug(u"sending message unencrypted") | 336 log.debug(u"sending message unencrypted") |
333 self.host.bridge.call('sendMessage', (None, self.host.sendError), to_jid.full(), msg, '', msg_type, extra) | 337 self.host.bridge.call('sendMessage', (None, self.host.sendError), to_jid.full(), msg, '', msg_type, extra) |
334 | 338 |
335 if msg_type != 'groupchat': | 339 if msg_type != 'groupchat': |
395 if priv_key is None: | 399 if priv_key is None: |
396 not_available() | 400 not_available() |
397 return | 401 return |
398 | 402 |
399 def cb(to_jid): | 403 def cb(to_jid): |
400 otrctx = self.context_manager.getContextForUser(to_jid, create=False) | 404 otrctx = self.context_manager.getContextForUser(to_jid, start=False) |
401 if otrctx is None: | 405 if otrctx is None: |
402 not_available() | 406 not_available() |
403 return | 407 return |
404 otr_version = otrctx.getUsedVersion() | 408 otr_version = otrctx.getUsedVersion() |
405 if otr_version == otr.context.OTR_VERSION_2: | 409 if otr_version == otr.context.OTR_VERSION_2: |