changeset e72d2b833933 in /home/hg/repos/gajim-plugins
author: lovetox forenjunkie@chello.at branches: details:gajim-plugins?cmd=changeset;node=e72d2b833933 description: Removing "GetDeviceKey" Button & fetch keys automatically
diffstat:
omemo/__init__.py | 49 +++++++++++++++---------------------------------- omemo/ui.py | 28 ---------------------------- 2 files changed, 15 insertions(+), 62 deletions(-)
diffs (176 lines):
diff -r 4e4d0772ade4 -r e72d2b833933 omemo/__init__.py --- a/omemo/__init__.py Thu Jun 02 21:36:13 2016 +0200 +++ b/omemo/__init__.py Fri Jun 03 18:24:20 2016 +0200 @@ -150,9 +150,6 @@ return
msg.msgtxt = plaintext - # msg.msg_.setBody(plaintext) - - # self.update_prekeys(account, msg_dict['sender_jid'])
contact_jid = msg.with_
@@ -170,7 +167,6 @@
if omemo_enabled: msg.msgtxt = '**Unencrypted** ' + msg.msgtxt - # msg.msg_.setBody(msg.msgtxt) # why do i need this?
try: gui = self.ui_list[account].get(jid, None) @@ -206,8 +202,6 @@ # bug? there must be a body or the message gets dropped from history msg.stanza.setBody(plaintext)
- self.update_prekeys(account, msg_dict['sender_jid']) - contact_jid = gajim.get_jid_without_resource(from_jid) if account in self.ui_list and \ contact_jid in self.ui_list[account]: @@ -291,7 +285,8 @@ if chat_control is not None: self.connect_ui(chat_control)
- self.update_prekeys(account_name, contact_jid) + # Look if Device Keys are missing and fetch them + self.are_keys_missing(account_name, contact_jid)
return True
@@ -323,18 +318,19 @@ else: log.warn(account_name + " ⇒ No OMEMO dev_keys for " + contact_jid)
- def are_keys_missing(self, contact): + def are_keys_missing(self, account_name, contact_jid): """ Used by the ui to set the state of the PreKeyButton. """ - account = contact.account.name - my_jid = gajim.get_jid_from_account(account) - state = self.get_omemo_state(account) + + my_jid = gajim.get_jid_from_account(account_name) + state = self.get_omemo_state(account_name) result = 0 - result += len(state.devices_without_sessions(str(contact.jid))) + result += len(state.devices_without_sessions(str(contact_jid))) result += len(state.own_devices_without_sessions(my_jid)) if result > 0: - log.warn(account + " ⇒ Missing keys for " + contact.jid + ": " + + log.warn(account_name + " ⇒ Missing keys for " + contact_jid + ": " + str(result)) - return result + log.warn('query keys now ...') + self.query_prekey(account_name, contact_jid)
@log_calls('OmemoPlugin') def handle_iq_received(self, event): @@ -349,13 +345,13 @@ del iq_ids_to_callbacks[id_]
@log_calls('OmemoPlugin') - def query_prekey(self, recipient): + def query_prekey(self, account_name, contact_jid): """ Calls OmemoPlugin.fetch_device_bundle_information() for each own or recipient device key missing. """ - account = recipient.account.name + account = account_name state = self.get_omemo_state(account) - to_jid = recipient.jid + to_jid = contact_jid my_jid = gajim.get_jid_from_account(account) for device_id in state.devices_without_sessions(to_jid): self.fetch_device_bundle_information(account, state, to_jid, @@ -399,8 +395,7 @@
This method tries to build an axolotl session when a PreKey bundle - is fetched. If building the axolotl session is successful it tries - to update the ui by calling `self.update_prekeys()`. + is fetched.
If a session can not be build it will fail silently but log the a warning. @@ -433,21 +428,7 @@ return
if state.build_session(recipient_id, device_id, bundle_dict): - self.update_prekeys(account_name, recipient_id) - - @log_calls('OmemoPlugin') - def update_prekeys(self, account, recipient_id): - """ Updates the "Get Prekeys" Button in the ui. - Parameters: - ---------- - account : str - The account name - recipient_id : str - The recipient jid - """ - if account in self.ui_list: - if recipient_id in self.ui_list[account]: - self.ui_list[account][recipient_id].update_prekeys() + log.warn(recipient_id + ' => session created')
@log_calls('OmemoPlugin') def announce_support(self, account): diff -r 4e4d0772ade4 -r e72d2b833933 omemo/ui.py --- a/omemo/ui.py Thu Jun 02 21:36:13 2016 +0200 +++ b/omemo/ui.py Fri Jun 03 18:24:20 2016 +0200 @@ -31,29 +31,6 @@ # from plugins.helpers import log
-class PreKeyButton(gtk.Button): - def __init__(self, plugin, contact): - super(PreKeyButton, self).__init__(label='Get Device Keys' + str( - plugin.are_keys_missing(contact))) - self.plugin = plugin - self.contact = contact - self.connect('clicked', self.on_click) - self.refresh() - - def refresh(self): - amount = self.plugin.are_keys_missing(self.contact) - if amount == 0: - self.set_no_show_all(True) - self.hide() - else: - self.set_no_show_all(False) - self.show() - self.set_label('Get Device Keys ' + str(amount)) - - def on_click(self, widget): - self.plugin.query_prekey(self.contact) - - class ClearDevicesButton(gtk.Button): def __init__(self, plugin, contact): super(ClearDevicesButton, self).__init__(label='Clear Devices') @@ -107,7 +84,6 @@ def __init__(self, plugin, chat_control, enabled): 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, self.contact)
@@ -116,7 +92,6 @@ else: self.encryption_disable()
- _add_widget(self.prekey_button, self.chat_control) _add_widget(self.checkbox, self.chat_control) _add_widget(self.clear_button, self.chat_control)
@@ -143,9 +118,6 @@ 'Received plaintext message! ' + 'Your next message will still be encrypted!', 'status', '', None)
- def update_prekeys(self): - self.prekey_button.refresh() -
class OMEMOConfigDialog(GajimPluginConfigDialog): def init(self):