changeset 1e80e2fdff27 in /home/hg/repos/gajim-plugins
author: lovetox forenjunkie@chello.at branches: details:gajim-plugins?cmd=changeset;node=1e80e2fdff27 description: show current OMEMO encryption state in chat Window
diffstat:
omemo/__init__.py | 19 ++++++++++++++++--- omemo/ui.py | 29 ++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 12 deletions(-)
diffs (78 lines):
diff -r 9f2826c1f9f4 -r 1e80e2fdff27 omemo/__init__.py --- a/omemo/__init__.py Sat May 28 17:33:52 2016 +0200 +++ b/omemo/__init__.py Sun May 29 13:06:19 2016 +0200 @@ -164,11 +164,24 @@ elif msg.stanza.getTag('body') and \ msg.stanza.getType() == 'chat': account = msg.conn.name + from_jid = str(msg.stanza.getAttr('from')) jid = gajim.get_jid_without_resource(from_jid) - gui = self.ui_list[account].get(jid, None) - if gui and gui.encryption_active(): - gui.plain_warning() + state = self.get_omemo_state(account) + omemo_enabled = state.encryption.is_active(jid) + + if omemo_enabled: + plaintext = msg.stanza.getBody() + msg.msgtxt = '**Unencrypted** ' + plaintext + msg.stanza.setBody(msg.msgtxt) + + try: + gui = self.ui_list[account].get(jid, None) + if gui and gui.encryption_active(): + gui.plain_warning() + except: + log.debug('No Ui present for ' + jid + + ', Ui Warning not shown')
@log_calls('OmemoPlugin') def handle_device_list_update(self, event): diff -r 9f2826c1f9f4 -r 1e80e2fdff27 omemo/ui.py --- a/omemo/ui.py Sat May 28 17:33:52 2016 +0200 +++ b/omemo/ui.py Sun May 29 13:06:19 2016 +0200 @@ -105,23 +105,34 @@ class Ui(object):
def __init__(self, plugin, chat_control, enabled): - contact = chat_control.contact - self.prekey_button = PreKeyButton(plugin, contact) + self.contact = chat_control.contact + self.chat_control = chat_control + self.prekey_button = PreKeyButton(plugin, self.contact) self.checkbox = Checkbox(plugin, chat_control) - self.clear_button = ClearDevicesButton(plugin, contact) + self.clear_button = ClearDevicesButton(plugin, self.contact)
- self.checkbox.set_active(enabled) - self.chat_control = chat_control + if enabled: + self.checkbox.set_active(True) + else: + self.encryption_disable()
- _add_widget(self.prekey_button, chat_control) - _add_widget(self.checkbox, chat_control) - _add_widget(self.clear_button, chat_control) + _add_widget(self.prekey_button, self.chat_control) + _add_widget(self.checkbox, self.chat_control) + _add_widget(self.clear_button, self.chat_control)
def encryption_active(self): return self.checkbox.get_active()
def encryption_disable(self): - return self.checkbox.set_active(False) + if self.checkbox.get_active(): + self.checkbox.set_active(False) + else: + log.info(self.contact.account.name + ' ⇒ Disable OMEMO for ' + + self.contact.jid) + self.chat_control._show_lock_image(False, 'OMEMO', False, True, + False) + self.chat_control.print_conversation_line( + u'OMEMO encryption disabled', 'status', '', None)
def activate_omemo(self): if not self.checkbox.get_active():