Commit 18e29ebc authored by Philipp Hörist's avatar Philipp Hörist

Add blocked contacts always to the default list

parent 5377fc82
......@@ -1752,6 +1752,8 @@ class Connection(CommonConnection, ConnectionHandlers):
return max_order
def block_contacts(self, contact_list, message):
if self.privacy_default_list is None:
self.privacy_default_list = 'block'
if not self.privacy_rules_supported:
if self.blocking_supported: #XEP-0191
iq = nbxmpp.Iq('set', xmlns='')
......@@ -1770,11 +1772,11 @@ class Connection(CommonConnection, ConnectionHandlers):
'value': contact.jid}
self.blocked_list.append(new_rule)
self.blocked_contacts.append(contact.jid)
self.set_privacy_list('block', self.blocked_list)
self.set_privacy_list(self.privacy_default_list, self.blocked_list)
if len(self.blocked_list) == 1:
self.set_active_list('block')
self.set_default_list('block')
self.get_privacy_list('block')
self.set_active_list(self.privacy_default_list)
self.set_default_list(self.privacy_default_list)
self.get_privacy_list(self.privacy_default_list)
def unblock_contacts(self, contact_list):
if not self.privacy_rules_supported:
......@@ -1796,15 +1798,15 @@ class Connection(CommonConnection, ConnectionHandlers):
if rule['action'] != 'deny' or rule['type'] != 'jid' \
or rule['value'] not in self.to_unblock:
self.new_blocked_list.append(rule)
self.set_privacy_list('block', self.new_blocked_list)
self.get_privacy_list('block')
self.set_privacy_list(self.privacy_default_list, self.new_blocked_list)
self.get_privacy_list(self.privacy_default_list)
if len(self.new_blocked_list) == 0:
self.blocked_list = []
self.blocked_contacts = []
self.blocked_groups = []
self.set_default_list('')
self.set_active_list('')
self.del_privacy_list('block')
self.del_privacy_list(self.privacy_default_list)
if not gajim.interface.roster.regroup:
show = gajim.SHOW_LIST[self.connected]
else: # accounts merged
......@@ -1826,11 +1828,11 @@ class Connection(CommonConnection, ConnectionHandlers):
'action': 'deny',
'value': group}
self.blocked_list.append(new_rule)
self.set_privacy_list('block', self.blocked_list)
self.set_privacy_list(self.privacy_default_list, self.blocked_list)
if len(self.blocked_list) == 1:
self.set_active_list('block')
self.set_default_list('block')
self.get_privacy_list('block')
self.set_active_list(self.privacy_default_list)
self.set_default_list(self.privacy_default_list)
self.get_privacy_list(self.privacy_default_list)
def unblock_group(self, group, contact_list):
if not self.privacy_rules_supported:
......@@ -1842,15 +1844,15 @@ class Connection(CommonConnection, ConnectionHandlers):
if rule['action'] != 'deny' or rule['type'] != 'group' or \
rule['value'] != group:
self.new_blocked_list.append(rule)
self.set_privacy_list('block', self.new_blocked_list)
self.get_privacy_list('block')
self.set_privacy_list(self.privacy_default_list, self.new_blocked_list)
self.get_privacy_list(self.privacy_default_list)
if len(self.new_blocked_list) == 0:
self.blocked_list = []
self.blocked_contacts = []
self.blocked_groups = []
self.set_default_list('')
self.set_active_list('')
self.del_privacy_list('block')
self.del_privacy_list(self.privacy_default_list)
if not gajim.interface.roster.regroup:
show = gajim.SHOW_LIST[self.connected]
else: # accounts merged
......@@ -2127,7 +2129,7 @@ class Connection(CommonConnection, ConnectionHandlers):
def _change_from_invisible(self):
if self.privacy_rules_supported:
if self.blocked_list:
self.activate_privacy_rule('block')
self.activate_privacy_rule(self.privacy_default_list)
else:
iq = self.build_privacy_rule('visible', 'allow')
self.connection.send(iq)
......@@ -2452,7 +2454,7 @@ class Connection(CommonConnection, ConnectionHandlers):
roster = gajim.interface.roster
if obj.conn.name != self.name:
return
if obj.list_name != 'block':
if obj.list_name != self.privacy_default_list:
return
self.blocked_contacts = []
self.blocked_groups = []
......
......@@ -568,7 +568,11 @@ class ConnectionVcard:
elif self.awaiting_answers[id_][0] == PRIVACY_ARRIVED:
del self.awaiting_answers[id_]
if iq_obj.getType() != 'error':
self.get_privacy_list('block')
for list_ in iq_obj.getQueryPayload():
if list_.getName() == 'default':
self.privacy_default_list = list_.getAttr('name')
self.get_privacy_list(self.privacy_default_list)
break
# Ask metacontacts before roster
self.get_metacontacts()
else:
......@@ -1443,6 +1447,8 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream):
self.awaiting_xmpp_ping_id = None
self.continue_connect_info = None
self.privacy_default_list = None
try:
self.sleeper = common.sleepy.Sleepy()
HAS_IDLE = True
......
......@@ -2769,6 +2769,7 @@ class GroupchatControl(ChatControlBase):
def on_block(self, widget, nick):
fjid = self.room_jid + '/' + nick
connection = gajim.connections[self.account]
default = connection.privacy_default_list
if fjid in connection.blocked_contacts:
return
max_order = connection.get_max_blocked_list_order()
......@@ -2778,15 +2779,16 @@ class GroupchatControl(ChatControlBase):
connection.blocked_list.append(new_rule)
connection.blocked_contacts.append(fjid)
self.draw_contact(nick)
connection.set_privacy_list('block', connection.blocked_list)
connection.set_privacy_list(default, connection.blocked_list)
if len(connection.blocked_list) == 1:
connection.set_active_list('block')
connection.set_default_list('block')
connection.get_privacy_list('block')
connection.set_active_list(default)
connection.set_default_list(default)
connection.get_privacy_list(default)
def on_unblock(self, widget, nick):
fjid = self.room_jid + '/' + nick
connection = gajim.connections[self.account]
default = connection.privacy_default_list
connection.new_blocked_list = []
# needed for draw_contact:
if fjid in connection.blocked_contacts:
......@@ -2797,15 +2799,15 @@ class GroupchatControl(ChatControlBase):
or rule['value'] != fjid:
connection.new_blocked_list.append(rule)
connection.set_privacy_list('block', connection.new_blocked_list)
connection.get_privacy_list('block')
connection.set_privacy_list(default, connection.new_blocked_list)
connection.get_privacy_list(default)
if len(connection.new_blocked_list) == 0:
connection.blocked_list = []
connection.blocked_contacts = []
connection.blocked_groups = []
connection.set_default_list('')
connection.set_active_list('')
connection.del_privacy_list('block')
connection.del_privacy_list(default)
if 'privay_list_block' in gajim.interface.instances[self.account]:
del gajim.interface.instances[self.account]\
['privay_list_block']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment