fix privacy lists: Don't use several time the same order number. Fixes #7352

This commit is contained in:
Yann Leboulanger 2013-05-26 12:58:19 +02:00
parent 55203d82ab
commit 63fd8e8277
2 changed files with 16 additions and 4 deletions

View File

@ -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)

View File

@ -2772,8 +2772,10 @@ class GroupchatControl(ChatControlBase):
connection = gajim.connections[self.account]
if fjid in connection.blocked_contacts:
return
new_rule = {'order': '1', 'type': 'jid', 'action': 'deny',
'value' : fjid, 'child': ['message', 'iq', 'presence-out']}
max_order = connection.get_max_blocked_list_order()
new_rule = {'order': str(max_order + 1), 'type': u'jid',
'action': u'deny', 'value' : fjid, 'child': ['message', 'iq',
'presence-out']}
connection.blocked_list.append(new_rule)
connection.blocked_contacts.append(fjid)
self.draw_contact(nick)