[omemo] Use extension point to add caps

This commit is contained in:
Philipp Hörist
2017-11-15 22:33:33 +01:00
parent 3318e2e193
commit 43ecb95ad6
2 changed files with 16 additions and 22 deletions

View File

@@ -9,7 +9,7 @@ from nbxmpp.simplexml import Node
from gajim.common import app from gajim.common import app
from gajim.common import ged from gajim.common import ged
from gajim.common import caps_cache from gajim.common import helpers
from gajim.common.connection_handlers_events import ( from gajim.common.connection_handlers_events import (
MessageReceivedEvent, MamMessageReceivedEvent, MessageNotSentEvent) MessageReceivedEvent, MamMessageReceivedEvent, MessageNotSentEvent)
@@ -126,11 +126,10 @@ class OMEMOConnection:
def activate(self): def activate(self):
""" Method called when the Plugin is activated in the PluginManager """ 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): if app.account_is_connected(self.account):
log.info('%s => Announce Support after Plugin Activation', log.info('%s => Announce Support after Plugin Activation',
self.account) self.account)
@@ -140,24 +139,13 @@ class OMEMOConnection:
def deactivate(self): def deactivate(self):
""" Method called when the Plugin is deactivated in the PluginManager """ 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]: self.query_for_bundles = []
app.gajim_optional_features[self.account].remove(NS_NOTIFY)
self._compute_caps_hash()
def _compute_caps_hash(self): @staticmethod
""" Computes the hash for Entity Capabilities and publishes it """ def update_caps(account):
app.caps_hash[self.account] = caps_cache.compute_caps_hash( if NS_NOTIFY not in app.gajim_optional_features[account]:
[app.gajim_identity], app.gajim_optional_features[account].append(NS_NOTIFY)
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)
def message_received(self, conn, obj, callback): def message_received(self, conn, obj, callback):
if obj.encrypted: if obj.encrypted:

View File

@@ -106,7 +106,8 @@ class OmemoPlugin(GajimPlugin):
'encryption_dialog' + self.encryption_name: ( 'encryption_dialog' + self.encryption_name: (
self.on_encryption_button_clicked, None), self.on_encryption_button_clicked, None),
'encryption_state' + self.encryption_name: ( '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) SUPPORTED_PERSONAL_USER_EVENTS.append(DevicelistPEP)
self.disabled_accounts = [] self.disabled_accounts = []
@@ -159,6 +160,11 @@ class OmemoPlugin(GajimPlugin):
continue continue
self.connections[account].deactivate() 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): def activate_encryption(self, chat_control):
if isinstance(chat_control, GroupchatControl): if isinstance(chat_control, GroupchatControl):
omemo_con = self.connections[chat_control.account] omemo_con = self.connections[chat_control.account]