From 77a6a02dc3e071c131131f4ea37090747e8ebd8b Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Mon, 21 Jun 2010 19:15:46 +0200 Subject: [PATCH] delete bookmarks from pubsub if server doesn't support publish-options. Fixes #5787 --- src/common/connection_handlers.py | 5 +++++ src/common/pubsub.py | 26 +++++++++++++++++++------- src/gui_interface.py | 16 ---------------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index b0897f0f1..7a3a41e12 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -354,6 +354,11 @@ class ConnectionDisco: self.pubsub_supported = True if features.__contains__(common.xmpp.NS_PUBSUB_PUBLISH_OPTIONS): self.pubsub_publish_options_supported = True + else: + # Remove stored bookmarks accessible to everyone. + our_jid = gajim.get_jid_from_account(self.name) + self.send_pb_purge(our_jid, 'storage:bookmarks') + self.send_pb_delete(our_jid, 'storage:bookmarks') if features.__contains__(common.xmpp.NS_BYTESTREAM): our_jid = helpers.parse_jid(gajim.get_jid_from_account(self.name) +\ '/' + self.server_resource) diff --git a/src/common/pubsub.py b/src/common/pubsub.py index 37db5a8ce..7cd83ff0f 100644 --- a/src/common/pubsub.py +++ b/src/common/pubsub.py @@ -109,25 +109,37 @@ class ConnectionPubSub: self.connection.send(query) - def send_pb_delete(self, jid, node): + def send_pb_purge(self, jid, node): + """ + Purge node: Remove all items + """ + if not self.connection or self.connected < 2: + return + query = xmpp.Iq('set', to=jid) + d = query.addChild('pubsub', namespace=xmpp.NS_PUBSUB_OWNER) + d = d.addChild('purge', {'node': node}) + + self.connection.send(query) + + def send_pb_delete(self, jid, node, on_ok=None, on_fail=None): """ Delete node """ if not self.connection or self.connected < 2: return query = xmpp.Iq('set', to=jid) - d = query.addChild('pubsub', namespace=xmpp.NS_PUBSUB) + d = query.addChild('pubsub', namespace=xmpp.NS_PUBSUB_OWNER) d = d.addChild('delete', {'node': node}) def response(con, resp, jid, node): - if resp.getType() == 'result': - self.dispatch('PUBSUB_NODE_REMOVED', (jid, node)) - else: + if resp.getType() == 'result' and on_ok: + on_ok(jid, node) + elif on_fail: msg = resp.getErrorMsg() - self.dispatch('PUBSUB_NODE_NOT_REMOVED', (jid, node, msg)) + on_fail(jid, node, msg) self.connection.SendAndCallForResponse(query, response, {'jid': jid, - 'node': node}) + 'node': node}) def send_pb_create(self, jid, node, configure = False, configure_form = None): """ diff --git a/src/gui_interface.py b/src/gui_interface.py index 369c27637..f43ac53c3 100644 --- a/src/gui_interface.py +++ b/src/gui_interface.py @@ -2064,19 +2064,6 @@ class Interface: checktext2, on_response_ok=on_ok, on_response_cancel=on_cancel, is_modal=False) - def handle_event_pubsub_node_removed(self, account, data): - # ('PUBSUB_NODE_REMOVED', account, (jid, node)) - if 'pep_services' in self.instances[account]: - if data[0] == gajim.get_jid_from_account(account): - self.instances[account]['pep_services'].node_removed(data[1]) - - def handle_event_pubsub_node_not_removed(self, account, data): - # ('PUBSUB_NODE_NOT_REMOVED', account, (jid, node, msg)) - if data[0] == gajim.get_jid_from_account(account): - dialogs.WarningDialog(_('PEP node was not removed'), - _('PEP node %(node)s was not removed: %(message)s') % { - 'node': data[1], 'message': data[2]}) - def handle_event_pep_received(self, account, data): # ('PEP_RECEIVED', account, (jid, pep_type)) jid = data[0] @@ -2188,9 +2175,6 @@ class Interface: 'INSECURE_SSL_CONNECTION': \ [self.handle_event_insecure_ssl_connection], 'INSECURE_PASSWORD': [self.handle_event_insecure_password], - 'PUBSUB_NODE_REMOVED': [self.handle_event_pubsub_node_removed], - 'PUBSUB_NODE_NOT_REMOVED': \ - [self.handle_event_pubsub_node_not_removed], 'JINGLE_INCOMING': [self.handle_event_jingle_incoming], 'JINGLE_CONNECTED': [self.handle_event_jingle_connected], 'JINGLE_DISCONNECTED': [self.handle_event_jingle_disconnected],