changeset ad2208598bfe in /home/hg/repos/gajim-plugins
author: Bahtiar `kalkin-` Gadimov <[email protected]>
branches:
details:gajim-plugins?cmd=changeset;node=ad2208598bfe
description: Simplified UI handling
- Remove UI.available logic. UI object is now only created if needed
- Remove UI.last_plain_msg logic. If a plain message is received we
just print a
warning as status msg
- Simplified OmemoState.device_ids_for
- Should fix #16 & #18
diffstat:
omemo/__init__.py | 64 +++++++++++++++++++++++++-----------------------------
omemo/state.py | 12 ----------
omemo/ui.py | 21 +++--------------
3 files changed, 34 insertions(+), 63 deletions(-)
diffs (189 lines):
diff -r 47bd067b9ae2 -r ad2208598bfe omemo/__init__.py
--- a/omemo/__init__.py Thu Jan 07 23:39:38 2016 +0100
+++ b/omemo/__init__.py Thu Jan 07 23:42:45 2016 +0100
@@ -166,10 +166,10 @@
devices_list = unpack_device_list_update(event)
if len(devices_list) == 0:
return False
- account = event.conn.name
+ account_name = event.conn.name
contact_jid = gajim.get_jid_without_resource(event.fjid)
- state = self.get_omemo_state(account)
- my_jid = gajim.get_jid_from_account(account)
+ state = self.get_omemo_state(account_name)
+ my_jid = gajim.get_jid_from_account(account_name)
if contact_jid == my_jid:
log.debug(state.name + ' ⇒ Received own device_list:' + str(
@@ -185,14 +185,19 @@
devices_list.append(state.own_device_id)
self.publish_own_devices_list(state)
else:
- log.debug(account + ' ⇒ Received device_list for ' + contact_jid +
- ':' + str(devices_list))
+ log.debug(account_name + ' ⇒ Received device_list for ' +
+ contact_jid + ':' + str(devices_list))
state.add_devices(contact_jid, devices_list)
- if account in self.ui_list and contact_jid in self.ui_list[
- account]:
- self.ui_list[account][contact_jid].toggle_omemo(True)
+ if account_name in self.ui_list and contact_jid not in
self.ui_list[
+ account_name]:
- self.update_prekeys(account, contact_jid)
+ chat_control = gajim.interface.msg_win_mgr.get_control(
+ contact_jid, account_name)
+
+ if chat_control is not None:
+ self.connect_ui(chat_control)
+
+ self.update_prekeys(account_name, contact_jid)
return True
@@ -210,13 +215,18 @@
@log_calls('OmemoPlugin')
def connect_ui(self, chat_control):
- account = chat_control.contact.account.name
- jid = chat_control.contact.jid
- if account not in self.ui_list:
- self.ui_list[account] = {}
- state = self.get_omemo_state(account)
- omemo_enabled = jid in state.omemo_enabled
- self.ui_list[account][jid] = Ui(self, chat_control, omemo_enabled)
+ account_name = chat_control.contact.account.name
+ contact_jid = chat_control.contact.jid
+ if account_name not in self.ui_list:
+ self.ui_list[account_name] = {}
+ state = self.get_omemo_state(account_name)
+ if contact_jid in state.device_ids:
+ log.debug(account_name + " ⇒ Adding OMEMO ui for " + contact_jid)
+ omemo_enabled = contact_jid in state.omemo_enabled
+ self.ui_list[account_name][contact_jid] = Ui(self, chat_control,
+ omemo_enabled)
+ else:
+ log.debug(account_name + " ⇒ No OMEMO dev_keys for " + contact_jid)
def are_keys_missing(self, contact):
""" Used by the ui to set the state of the PreKeyButton. """
@@ -226,6 +236,8 @@
result = 0
result += len(state.devices_without_sessions(str(contact.jid)))
result += len(state.own_devices_without_sessions(my_jid))
+ log.debug(account + " ⇒ Missing keys for " + contact.jid + ": " + str(
+ result))
return result
@log_calls('OmemoPlugin')
@@ -269,8 +281,8 @@
device_id : int
The device_id for which we are missing an axolotl session
"""
- log.debug(state.name + '→ Fetch bundle device ' + str(device_id) + '#'
+
- jid)
+ log.debug(state.name + '→ Fetch bundle device ' + str(device_id) + '#'
+ + jid)
iq = BundleInformationQuery(jid, device_id)
iq_id = str(iq.getAttr('id'))
iq_ids_to_callbacks[iq_id] = \
@@ -437,22 +449,6 @@
state = self.get_omemo_state(account)
state.omemo_enabled.remove(contact.jid)
- @log_calls('OmemoPlugin')
- def has_omemo(self, contact):
- """ Used by the ui to find out if omemo controls should be displayed
for
- the given contact.
-
- Returns
- -------
- bool
- True if there are known device_ids/clients supporting OMEMO
- """
- account = contact.account.name
- state = self.get_omemo_state(account)
- if state.device_ids_for(contact):
- return True
- return False
-
@log_calls('OmemoPlugin')
def anydup(thelist):
diff -r 47bd067b9ae2 -r ad2208598bfe omemo/state.py
--- a/omemo/state.py Thu Jan 07 23:39:38 2016 +0100
+++ b/omemo/state.py Thu Jan 07 23:42:45 2016 +0100
@@ -95,18 +95,6 @@
def own_device_id_published(self):
return self.own_device_id in self.own_devices
- def device_ids_for(self, contact):
- account = contact.account.name
- log.debug(account + ' ⇒ Searching device_ids for contact ' +
- contact.jid)
- if contact.jid not in self.device_ids:
- log.debug(contact.jid + '¬∈ devices_ids[' + account + ']')
- return None
-
- log.debug(account + ' ⇒ found device_ids ' + str(self.device_ids[
- contact.jid]))
- return self.device_ids[contact.jid]
-
@property
def bundle(self):
prekeys = [
diff -r 47bd067b9ae2 -r ad2208598bfe omemo/ui.py
--- a/omemo/ui.py Thu Jan 07 23:39:38 2016 +0100
+++ b/omemo/ui.py Thu Jan 07 23:42:45 2016 +0100
@@ -91,21 +91,17 @@
send_button_pos = actions_hbox.child_get_property(send_button, 'position')
actions_hbox.add_with_properties(widget, 'position', send_button_pos - 2,
'expand', False)
+ widget.show_all()
class Ui(object):
- last_msg_plain = True
-
def __init__(self, plugin, chat_control, enabled):
contact = chat_control.contact
self.prekey_button = PreKeyButton(plugin, contact)
self.checkbox = Checkbox(plugin, chat_control)
self.clear_button = ClearDevicesButton(plugin, contact)
- available = plugin.has_omemo(contact)
- self.toggle_omemo(available)
-
self.checkbox.set_active(enabled)
self.chat_control = chat_control
@@ -113,14 +109,6 @@
_add_widget(self.checkbox, chat_control)
_add_widget(self.clear_button, chat_control)
- def toggle_omemo(self, available):
- if available:
- self.checkbox.set_no_show_all(False)
- self.checkbox.show()
- else:
- self.checkbox.set_no_show_all(True)
- self.checkbox.hide()
-
def encryption_active(self):
return self.checkbox.get_active()
@@ -132,10 +120,9 @@
self.checkbox.set_active(True)
def plain_warning(self):
- if not self.last_msg_plain:
- self.chat_control.print_conversation_line(
- 'Received plaintext message!', 'status', '', None)
- self.last_msg_plain = True
+ self.chat_control.print_conversation_line(
+ 'Received plaintext message! ' +
+ 'Your next message will still be encrypted!', 'status', '', None)
def update_prekeys(self):
self.prekey_button.refresh()
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits