Mercurial > libervia-web
diff src/browser/sat_browser/plugin_sec_otr.py @ 536:048ae7314156
browser_side: temporary way to display the OTR state in the LiberviaWidget header
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 07 Sep 2014 16:40:33 +0200 |
parents | 331cb6ea0235 |
children | cd492c18b366 |
line wrap: on
line diff
--- a/src/browser/sat_browser/plugin_sec_otr.py Fri Sep 05 19:29:35 2014 +0200 +++ b/src/browser/sat_browser/plugin_sec_otr.py Sun Sep 07 16:40:33 2014 +0200 @@ -52,6 +52,13 @@ 'REQUIRE_ENCRYPTION': False, } +# list a couple of texts (untrusted, trusted) for each state +OTR_MSG_STATES = { + otr.context.STATE_PLAINTEXT: [_('none'), _('none')], + otr.context.STATE_ENCRYPTED: [_('untrusted'), _('trusted')], + otr.context.STATE_FINISHED: [_('finished'), _('finished')] +} + class Context(otr.context.Context): @@ -101,21 +108,28 @@ def messageErrorCb(self, error): log.error('error occured: %s' % error) + @classmethod + def getInfoText(self, state='', trust=''): + if not state: + state = OTR_MSG_STATES.keys()[0] + return 'Encryption: %s' % OTR_MSG_STATES[state][1 if trust else 0] + def setStateCb(self, msg_state, status): - other_jid_s = self.peer.full() - feedback = _(u"Error: the state of the conversation with %s is unknown!") - if status == otr.context.STATUS_AKE_INIT: return - elif status == otr.context.STATUS_SEND_QUERY: + other_jid_s = self.peer.full() + feedback = _(u"Error: the state of the conversation with %s is unknown!") + trust = self.getCurrentTrust() + + if status == otr.context.STATUS_SEND_QUERY: if msg_state == otr.context.STATE_ENCRYPTED: feedback = _('Attempting to refresh the private conversation with %s...') else: feedback = _('Attempting to start a private conversation with %s...') elif status == otr.context.STATUS_AKE_SUCCESS: - trusted_str = _(u"Verified") if self.getCurrentTrust() else _(u"Unverified") + trusted_str = _(u"Verified") if trust else _(u"Unverified") if msg_state == otr.context.STATE_ENCRYPTED: feedback = trusted_str + (u" conversation with %s started. Your client is not logging this conversation.") else: @@ -129,7 +143,7 @@ elif msg_state == otr.context.STATE_FINISHED: feedback = _("%s has ended his/her private conversation with you; you should do the same.") - self.host.newMessageCb(self.peer, feedback % other_jid_s, C.MESS_TYPE_INFO, self.host.whoami, {}) + self.host.newMessageCb(self.peer, feedback % other_jid_s, C.MESS_TYPE_INFO, self.host.whoami, {'header_info': Context.getInfoText(msg_state, trust)}) def setCurrentTrust(self, new_trust='', act='asked', type_='trust'): log.debug("setCurrentTrust: trust={trust}, act={act}, type={type}".format(type=type_, trust=new_trust, act=act)) @@ -150,7 +164,7 @@ otr.context.Context.setCurrentTrust(self, new_trust) if old_trust != new_trust: feedback = _("The privacy status of the current conversation is now: {state}").format(state='Private' if new_trust else 'Unverified') - self.host.newMessageCb(self.peer, feedback, C.MESS_TYPE_INFO, self.host.whoami, {}) + self.host.newMessageCb(self.peer, feedback, C.MESS_TYPE_INFO, self.host.whoami, {'header_info': Context.getInfoText(self.state, new_trust)}) def fingerprintAuthCb(self): """OTR v2 authentication using manual fingerprint comparison"""