Mercurial > libervia-web
comparison src/browser/sat_browser/plugin_sec_otr.py @ 559:77372641e05d
browser_side (plugin OTR): display the correct icons on opening the window + auto-open on accepted invitation
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 23 Sep 2014 13:57:36 +0200 |
parents | d0114855d6d4 |
children | b07f0fe2763a |
comparison
equal
deleted
inserted
replaced
558:b38629924602 | 559:77372641e05d |
---|---|
30 | 30 |
31 from constants import Const as C | 31 from constants import Const as C |
32 import jid | 32 import jid |
33 import otrjs_wrapper as otr | 33 import otrjs_wrapper as otr |
34 import dialog | 34 import dialog |
35 import panels | |
36 | |
35 | 37 |
36 NS_OTR = "otr_plugin" | 38 NS_OTR = "otr_plugin" |
37 PRIVATE_KEY = "PRIVATE KEY" | 39 PRIVATE_KEY = "PRIVATE KEY" |
38 MAIN_MENU = D_('OTR encryption') | 40 MAIN_MENU = D_('OTR encryption') |
39 DIALOG_EOL = "<br />" | 41 DIALOG_EOL = "<br />" |
363 self.last_resources = {} | 365 self.last_resources = {} |
364 self.host.bridge._registerMethods(["skipOTR"]) | 366 self.host.bridge._registerMethods(["skipOTR"]) |
365 | 367 |
366 @classmethod | 368 @classmethod |
367 def getInfoText(self, state=otr.context.STATE_PLAINTEXT, trust=''): | 369 def getInfoText(self, state=otr.context.STATE_PLAINTEXT, trust=''): |
370 """Get the widget info text for a certain message state and trust. | |
371 | |
372 @param state (str): message state | |
373 @param trust (str): trust | |
374 @return: str | |
375 """ | |
368 if not state: | 376 if not state: |
369 state = OTR_MSG_STATES.keys()[0] | 377 state = OTR_MSG_STATES.keys()[0] |
370 return OTR_MSG_STATES[state][1 if trust else 0] | 378 return OTR_MSG_STATES[state][1 if trust else 0] |
379 | |
380 def infoTextCallback(self, other_jid, cb): | |
381 """Get the current info text for a conversation and run a callback. | |
382 | |
383 @param other_jid (JID): JID of the correspondant | |
384 @paam cb (callable): method to be called with the computed info text | |
385 """ | |
386 def gotResource(other_jid): | |
387 otrctx = self.context_manager.getContextForUser(other_jid, start=False) | |
388 if otrctx is None: | |
389 cb(OTR.getInfoText()) | |
390 else: | |
391 cb(OTR.getInfoText(otrctx.state, otrctx.getCurrentTrust())) | |
392 | |
393 self.fixResource(other_jid, gotResource) | |
371 | 394 |
372 def inhibitMenus(self): | 395 def inhibitMenus(self): |
373 """Tell the caller which dynamic menus should be inhibited""" | 396 """Tell the caller which dynamic menus should be inhibited""" |
374 return ["OTR"] # menu categories name to inhibit | 397 return ["OTR"] # menu categories name to inhibit |
375 | 398 |
421 def cb(jid): | 444 def cb(jid): |
422 otrctx = self.context_manager.getContextForUser(jid, start=False) | 445 otrctx = self.context_manager.getContextForUser(jid, start=False) |
423 if otrctx is None: | 446 if otrctx is None: |
424 def confirm(confirm): | 447 def confirm(confirm): |
425 if confirm: | 448 if confirm: |
449 self.host.getOrCreateLiberviaWidget(panels.ChatPanel, jid) | |
426 decrypt(self.context_manager.startContext(jid)) | 450 decrypt(self.context_manager.startContext(jid)) |
427 else: | 451 else: |
428 # FIXME: plain text messages with whitespaces would be lost here when WHITESPACE_START_AKE is True | 452 # FIXME: plain text messages with whitespaces would be lost here when WHITESPACE_START_AKE is True |
429 pass | 453 pass |
430 key = self.context_manager.account.privkey | 454 key = self.context_manager.account.privkey |