diff options
author | Philipp Hörist <forenjunkie@chello.at> | 2017-11-16 00:33:33 +0300 |
---|---|---|
committer | Philipp Hörist <forenjunkie@chello.at> | 2017-11-16 01:45:16 +0300 |
commit | 43ecb95ad6a711d45e34fdc28fcba0a5976ef69b (patch) | |
tree | 1d4abfeb04cd19aac32cb0ad6b79fec233058403 | |
parent | 3318e2e1938e3305bdf092d5cf09292a25d39ca5 (diff) |
[omemo] Use extension point to add caps
-rw-r--r-- | omemo/omemo_connection.py | 32 | ||||
-rw-r--r-- | omemo/omemoplugin.py | 8 |
2 files changed, 17 insertions, 23 deletions
diff --git a/omemo/omemo_connection.py b/omemo/omemo_connection.py index a58c80d..4d8818f 100644 --- a/omemo/omemo_connection.py +++ b/omemo/omemo_connection.py @@ -9,7 +9,7 @@ from nbxmpp.simplexml import Node from gajim.common import app from gajim.common import ged -from gajim.common import caps_cache +from gajim.common import helpers from gajim.common.connection_handlers_events import ( MessageReceivedEvent, MamMessageReceivedEvent, MessageNotSentEvent) @@ -126,11 +126,10 @@ class OMEMOConnection: def activate(self): """ Method called when the Plugin is activated in the PluginManager """ - # self.query_for_bundles = [] + if app.caps_hash[self.account] != '': + # Gajim has already a caps hash calculated, update it + helpers.update_optional_features(self.account) - if NS_NOTIFY not in app.gajim_optional_features[self.account]: - app.gajim_optional_features[self.account].append(NS_NOTIFY) - self._compute_caps_hash() if app.account_is_connected(self.account): log.info('%s => Announce Support after Plugin Activation', self.account) @@ -140,24 +139,13 @@ class OMEMOConnection: def deactivate(self): """ Method called when the Plugin is deactivated in the PluginManager - - Removes OMEMO from the Entity Capabilities list """ - if NS_NOTIFY in app.gajim_optional_features[self.account]: - app.gajim_optional_features[self.account].remove(NS_NOTIFY) - self._compute_caps_hash() - - def _compute_caps_hash(self): - """ Computes the hash for Entity Capabilities and publishes it """ - app.caps_hash[self.account] = caps_cache.compute_caps_hash( - [app.gajim_identity], - app.gajim_common_features + - app.gajim_optional_features[self.account]) - # re-send presence with new hash - connected = app.connections[self.account].connected - if connected > 1 and app.SHOW_LIST[connected] != 'invisible': - app.connections[self.account].change_status( - app.SHOW_LIST[connected], app.connections[self.account].status) + self.query_for_bundles = [] + + @staticmethod + def update_caps(account): + if NS_NOTIFY not in app.gajim_optional_features[account]: + app.gajim_optional_features[account].append(NS_NOTIFY) def message_received(self, conn, obj, callback): if obj.encrypted: diff --git a/omemo/omemoplugin.py b/omemo/omemoplugin.py index 9c74f93..0133e81 100644 --- a/omemo/omemoplugin.py +++ b/omemo/omemoplugin.py @@ -106,7 +106,8 @@ class OmemoPlugin(GajimPlugin): 'encryption_dialog' + self.encryption_name: ( self.on_encryption_button_clicked, None), 'encryption_state' + self.encryption_name: ( - self.encryption_state, None)} + self.encryption_state, None), + 'update_caps': (self._update_caps, None)} SUPPORTED_PERSONAL_USER_EVENTS.append(DevicelistPEP) self.disabled_accounts = [] @@ -159,6 +160,11 @@ class OmemoPlugin(GajimPlugin): continue self.connections[account].deactivate() + def _update_caps(self, account): + if account == 'Local': + return + self.connections[account].update_caps(account) + def activate_encryption(self, chat_control): if isinstance(chat_control, GroupchatControl): omemo_con = self.connections[chat_control.account] |