From 6429cc9dddf147f2370dd0302d349e6311285a1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Tue, 20 Nov 2018 17:33:46 +0100 Subject: [PATCH] [omemo] Publish devicelist with id 'current' --- omemo/gtk/config.py | 2 +- omemo/omemo_connection.py | 35 ++++++++++++----------------------- omemo/xmpp.py | 18 ------------------ 3 files changed, 13 insertions(+), 42 deletions(-) diff --git a/omemo/gtk/config.py b/omemo/gtk/config.py index 8d62778..bfef4c1 100644 --- a/omemo/gtk/config.py +++ b/omemo/gtk/config.py @@ -171,7 +171,7 @@ class OMEMOConfigDialog(GajimPluginConfigDialog): def cleardevice_button_clicked_cb(self, button, *args): active = self._ui.get_object('account_combobox').get_active() account = self.account_store[active][0] - self.plugin.connections[account].clear_device_list() + self.plugin.connections[account].publish_own_devices_list(new=True) self.update_context_list() def refresh_button_clicked_cb(self, button, *args): diff --git a/omemo/omemo_connection.py b/omemo/omemo_connection.py index 42d23db..5f388d5 100644 --- a/omemo/omemo_connection.py +++ b/omemo/omemo_connection.py @@ -17,9 +17,9 @@ from gajim.plugins.plugins_i18n import _ from omemo.xmpp import ( NS_NOTIFY, NS_OMEMO, NS_EME, NS_HINTS, BundleInformationAnnouncement, - BundleInformationQuery, DeviceListAnnouncement, DevicelistQuery, + BundleInformationQuery, DevicelistQuery, OmemoMessage, successful, unpack_device_bundle, - unpack_device_list_update, unpack_encrypted) + unpack_device_list_update, unpack_encrypted, NS_DEVICE_LIST) from omemo.omemo.state import OmemoState ALLOWED_TAGS = [('request', nbxmpp.NS_RECEIPTS), @@ -677,13 +677,19 @@ class OMEMOConnection: devices_list = list(set(devices_list)) self.omemo.set_own_devices(devices_list) + list_node = Node('list', attrs={'xmlns': NS_OMEMO}) + for device in devices_list: + list_node.addChild('device').setAttr('id', device) + + con = app.connections[self.account] + con.get_module('PubSub').send_pb_publish( + '', NS_DEVICE_LIST, list_node, 'current', + cb=self.device_list_publish_result) + log.info('%s => Publishing own Devices: %s', self.account, devices_list) - device_announce = DeviceListAnnouncement(devices_list) - self.send_with_callback(device_announce, - self.device_list_publish_result) - def device_list_publish_result(self, stanza): + def device_list_publish_result(self, _con, stanza): if not nbxmpp.isResultNode(stanza): log.error('%s => Publishing devicelist failed: %s', self.account, stanza.getError()) @@ -852,23 +858,6 @@ class OMEMOConnection: self.account, stanza.getError()) self.publish_own_devices_list(new=True) - def clear_device_list(self): - """ Overwrite the current devicelist on the server with only - our device id. - """ - if not app.account_is_connected(self.account): - return - devices_list = [self.omemo.own_device_id] - self.omemo.set_own_devices(devices_list) - - log.info('%s => Clearing devices_list %s', self.account, devices_list) - device_announce = DeviceListAnnouncement(devices_list) - self.send_with_callback(device_announce, self.clear_device_list_result) - - @staticmethod - def clear_device_list_result(stanza): - log.info(stanza) - @staticmethod def print_msg_to_log(stanza): """ Prints a stanza in a fancy way to the log """ diff --git a/omemo/xmpp.py b/omemo/xmpp.py index 0b04080..b74752d 100644 --- a/omemo/xmpp.py +++ b/omemo/xmpp.py @@ -57,24 +57,6 @@ class PubsubNode(Node): self.addChild(node=data) -class DeviceListAnnouncement(Iq): - def __init__(self, device_list): - assert isinstance(device_list, list) - assert len(device_list) > 0 - id_ = app.get_an_id() - attrs = {'id': id_} - Iq.__init__(self, typ='set', attrs=attrs) - - list_node = Node('list', attrs={'xmlns': NS_OMEMO}) - for device in device_list: - list_node.addChild('device').setAttr('id', device) - - publish = PublishNode(NS_DEVICE_LIST, list_node) - pubsub = PubsubNode(publish) - - self.addChild(node=pubsub) - - class OmemoMessage(Node): def __init__(self, msg_dict): # , contact_jid, key, iv, payload, dev_id, my_dev_id):