changeset f0fc5cb50a8c in /home/hg/repos/gajim-plugins

author: lovetox <[email protected]>
branches: 
details:gajim-plugins?cmd=changeset;node=f0fc5cb50a8c
description: Refactor publishing bundle information

diffstat:

 omemo/__init__.py    |  71 +++++++++++++++++++++++++++------------------------
 omemo/omemo/state.py |   4 ++-
 2 files changed, 40 insertions(+), 35 deletions(-)

diffs (172 lines):

diff -r 67652b4b3a2a -r f0fc5cb50a8c omemo/__init__.py
--- a/omemo/__init__.py Sat Jul 23 00:59:45 2016 +0200
+++ b/omemo/__init__.py Sat Jul 23 02:26:58 2016 +0200
@@ -35,8 +35,9 @@
 from .ui import Ui
 from .xmpp import (
     NS_NOTIFY, NS_OMEMO, BundleInformationAnnouncement, BundleInformationQuery,
-    DeviceListAnnouncement, DevicelistQuery, DevicelistPEP, OmemoMessage, 
successful,
-    unpack_device_bundle, unpack_device_list_update, unpack_encrypted)
+    DeviceListAnnouncement, DevicelistQuery, DevicelistPEP, OmemoMessage,
+    successful, unpack_device_bundle, unpack_device_list_update,
+    unpack_encrypted)
 
 
 iq_ids_to_callbacks = {}
@@ -80,8 +81,10 @@
             (ged.PRECORE, self.handle_outgoing_event),
         }
         self.config_dialog = ui.OMEMOConfigDialog(self)
-        self.gui_extension_points = {'chat_control': (self.connect_ui, 
self.disconnect_ui)}
+        self.gui_extension_points = {'chat_control': (self.connect_ui,
+                                                      self.disconnect_ui)}
         SUPPORTED_PERSONAL_USER_EVENTS.append(DevicelistPEP)
+        self.plugin = self
         self.announced = []
 
     @log_calls('OmemoPlugin')
@@ -96,14 +99,8 @@
 
             my_jid = gajim.get_jid_from_account(account)
 
-            self.omemo_states[account] = OmemoState(my_jid, conn, account)
-
-        if account not in self.announced:
-            if gajim.account_is_connected(account):
-                log.debug(account +
-                          ' => Announce Support after Plugin Activation')
-                self.announced.append(account)
-                self.announce_support(account)
+            self.omemo_states[account] = OmemoState(my_jid, conn, account,
+                                                    self.plugin)
 
         return self.omemo_states[account]
 
@@ -118,21 +115,31 @@
         log.info(str(account) + " => Gajim E2E encryption disabled")
 
     @log_calls('OmemoPlugin')
-    def signed_in(self, show):
+    def signed_in(self, event):
         """
             On sign in announce OMEMO support for each account.
         """
-        account = show.conn.name
+        account = event.conn.name
         log.debug(account +
                   ' => Announce Support after Sign In')
         self.announced.append(account)
-        self.announce_support(account)
+        self.publish_bundle(account)
+        self.query_own_devicelist(account)
 
     @log_calls('OmemoPlugin')
     def activate(self):
         if NS_NOTIFY not in gajim.gajim_common_features:
             gajim.gajim_common_features.append(NS_NOTIFY)
         self._compute_caps_hash()
+        # Publish bundle information
+        for account in gajim.connections:
+            if account not in self.announced:
+                if gajim.account_is_connected(account):
+                    log.debug(account +
+                              ' => Announce Support after Plugin Activation')
+                    self.announced.append(account)
+                    self.publish_bundle(account)
+                    self.query_own_devicelist(account)
 
     @log_calls('OmemoPlugin')
     def deactivate(self):
@@ -322,7 +329,7 @@
         devices_list = list(set(devices_list))
         state.set_own_devices(devices_list)
 
-        log.debug(account_name + ' => Publishing own devices_list ' + str(
+        log.debug(account_name + ' => Publishing own Devices: ' + str(
             devices_list))
         iq = DeviceListAnnouncement(devices_list)
         gajim.connections[account_name].connection.send(iq)
@@ -455,12 +462,18 @@
                     WarnIfUndecidedFingerprints()
 
     @log_calls('OmemoPlugin')
-    def announce_support(self, account):
-        """ Announce OMEMO support for an account via PEP.
+    def query_own_devicelist(self, account):
+        my_jid = gajim.get_jid_from_account(account)
+        iq = DevicelistQuery(my_jid)
+        gajim.connections[account].connection.send(iq)
+        log.info(account + ' => Querry own devicelist ...')
+        id_ = str(iq.getAttr("id"))
+        iq_ids_to_callbacks[id_] = lambda stanza: \
+            self.handle_devicelist_result(account, stanza)
 
-            In order for other clients/devices to be able to initiate a session
-            with gajim, it first has to announce itself by adding its device ID
-            to the devicelist PEP node.
+    @log_calls('OmemoPlugin')
+    def publish_bundle(self, account):
+        """ Publish our bundle information to the PEP node.
 
             Parameters
             ----------
@@ -476,16 +489,13 @@
         iq = BundleInformationAnnouncement(state.bundle, state.own_device_id)
         gajim.connections[account].connection.send(iq)
         id_ = str(iq.getAttr("id"))
-        log.info(account + " => Announcing OMEMO support via PEP")
+        log.info(account + " => Publishing bundle ...")
         iq_ids_to_callbacks[id_] = lambda stanza: \
-            self.handle_announcement_result(account, stanza)
+            self.handle_publish_result(account, stanza)
 
     @log_calls('OmemoPlugin')
-    def handle_announcement_result(self, account, stanza):
-        """ Query own device list if announcement was successfull.
-
-            If the OMEMO support announcement was successfull own device
-            list is queried.
+    def handle_publish_result(self, account, stanza):
+        """ Log if publishing our bundle was successful
 
             Parameters
             ----------
@@ -494,15 +504,8 @@
             stanza
                 The stanza object received from callback
         """
-        my_jid = gajim.get_jid_from_account(account)
-        iq = DevicelistQuery(my_jid)
         if successful(stanza):
             log.info(account + ' => Publishing bundle was successful')
-            gajim.connections[account].connection.send(iq)
-            log.info(account + ' => Querry own Devicelist')
-            id_ = str(iq.getAttr("id"))
-            iq_ids_to_callbacks[id_] = lambda stanza: \
-                self.handle_devicelist_result(account, stanza)
         else:
             log.error(account + ' => Publishing bundle was NOT successful')
 
diff -r 67652b4b3a2a -r f0fc5cb50a8c omemo/omemo/state.py
--- a/omemo/omemo/state.py      Sat Jul 23 00:59:45 2016 +0200
+++ b/omemo/omemo/state.py      Sat Jul 23 02:26:58 2016 +0200
@@ -47,12 +47,13 @@
 
 
 class OmemoState:
-    def __init__(self, own_jid, connection, account):
+    def __init__(self, own_jid, connection, account, plugin):
         """ Instantiates an OmemoState object.
 
             :param connection: an :py:class:`sqlite3.Connection`
         """
         self.account = account
+        self.plugin = plugin
         self.session_ciphers = {}
         self.own_jid = own_jid
         self.device_ids = {}
@@ -356,3 +357,4 @@
             self.store.preKeyStore.generateNewPreKeys(newKeys)
             log.info(self.account + ' => ' + str(newKeys) +
                      ' PreKeys created')
+            self.plugin.publish_bundle(self.account)
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to