From ae51adcee2732efb3e767bd3535081b7cb05ab42 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger <asterix@lagaule.org> Date: Sun, 26 May 2013 12:58:19 +0200 Subject: [PATCH] fix privacy lists: Don't use several time the same order number. Fixes #7352 --- src/common/connection.py | 14 ++++++++++++-- src/groupchat_control.py | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 978e601a2c..4ed55177a7 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -1603,6 +1603,14 @@ class Connection(CommonConnection, ConnectionHandlers): iq.setQuery().setTag('active', {'name': name}) self.connection.send(iq) + def get_max_blocked_list_order(self): + max_order = 0 + for rule in self.blocked_list: + order = int(rule['order']) + if order > max_order: + max_order = order + return max_order + def block_contacts(self, contact_list, message): if not self.privacy_rules_supported: if self.blocking_supported: #XEP-0191 @@ -1616,7 +1624,8 @@ class Connection(CommonConnection, ConnectionHandlers): return for contact in contact_list: self.send_custom_status('offline', message, contact.jid) - new_rule = {'order': '1', 'type': 'jid', 'action': 'deny', + max_order = self.get_max_blocked_list_order() + new_rule = {'order': str(max_order + 1), 'type': 'jid', 'action': 'deny', 'value' : contact.jid, 'child': ['message', 'iq', 'presence-out']} self.blocked_list.append(new_rule) @@ -1672,7 +1681,8 @@ class Connection(CommonConnection, ConnectionHandlers): self.blocked_groups.append(group) for contact in contact_list: self.send_custom_status('offline', message, contact.jid) - new_rule = {'order': '1', 'type': 'group', 'action': 'deny', + max_order = self.get_max_blocked_list_order() + new_rule = {'order': str(max_order + 1), 'type': 'group', 'action': 'deny', 'value' : group, 'child': ['message', 'iq', 'presence-out']} self.blocked_list.append(new_rule) self.set_privacy_list('block', self.blocked_list) diff --git a/src/groupchat_control.py b/src/groupchat_control.py index 64c75adafc..cf2cbae7e3 100644 --- a/src/groupchat_control.py +++ b/src/groupchat_control.py @@ -2757,7 +2757,8 @@ class GroupchatControl(ChatControlBase): connection = gajim.connections[self.account] if fjid in connection.blocked_contacts: return - new_rule = {'order': u'1', 'type': u'jid', 'action': u'deny', + max_order = connection.get_max_blocked_list_order() + new_rule = {'order': str(max_order + 1), 'type': u'jid', 'action': u'deny', 'value' : fjid, 'child': [u'message', u'iq', u'presence-out']} connection.blocked_list.append(new_rule) connection.blocked_contacts.append(fjid) -- GitLab