Merge branch 'master' into 'master'
Fix Privacy Lists Closes #8476 See merge request !68
This commit is contained in:
commit
49a5bb631c
|
@ -1733,16 +1733,6 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
iq = self.build_invisible_rule()
|
||||
self.connection.send(iq)
|
||||
|
||||
def activate_privacy_rule(self, name):
|
||||
"""
|
||||
Activate a privacy rule
|
||||
"""
|
||||
if not gajim.account_is_connected(self.name):
|
||||
return
|
||||
iq = nbxmpp.Iq('set', nbxmpp.NS_PRIVACY, xmlns='')
|
||||
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:
|
||||
|
@ -1752,6 +1742,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='')
|
||||
|
@ -1764,16 +1756,15 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
for contact in contact_list:
|
||||
self.send_custom_status('offline', message, contact.jid)
|
||||
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']}
|
||||
new_rule = {'order': str(max_order + 1),
|
||||
'type': 'jid',
|
||||
'action': 'deny',
|
||||
'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_default_list(self.privacy_default_list)
|
||||
|
||||
def unblock_contacts(self, contact_list):
|
||||
if not self.privacy_rules_supported:
|
||||
|
@ -1795,15 +1786,14 @@ 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')
|
||||
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)
|
||||
else:
|
||||
self.set_privacy_list(self.privacy_default_list, self.new_blocked_list)
|
||||
if not gajim.interface.roster.regroup:
|
||||
show = gajim.SHOW_LIST[self.connected]
|
||||
else: # accounts merged
|
||||
|
@ -1820,14 +1810,14 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
for contact in contact_list:
|
||||
self.send_custom_status('offline', message, contact.jid)
|
||||
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']}
|
||||
new_rule = {'order': str(max_order + 1),
|
||||
'type': 'group',
|
||||
'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_default_list(self.privacy_default_list)
|
||||
|
||||
def unblock_group(self, group, contact_list):
|
||||
if not self.privacy_rules_supported:
|
||||
|
@ -1839,15 +1829,14 @@ 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')
|
||||
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)
|
||||
else:
|
||||
self.set_privacy_list(self.privacy_default_list, self.new_blocked_list)
|
||||
if not gajim.interface.roster.regroup:
|
||||
show = gajim.SHOW_LIST[self.connected]
|
||||
else: # accounts merged
|
||||
|
@ -1888,7 +1877,7 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
if iq_obj.getType() == 'error': # server doesn't support privacy lists
|
||||
return
|
||||
# active the privacy rule
|
||||
self.activate_privacy_rule('invisible')
|
||||
self.set_active_list('invisible')
|
||||
self.connected = gajim.SHOW_LIST.index('invisible')
|
||||
self.status = msg
|
||||
priority = gajim.get_priority(self.name, 'invisible')
|
||||
|
@ -2123,12 +2112,7 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
|
||||
def _change_from_invisible(self):
|
||||
if self.privacy_rules_supported:
|
||||
if self.blocked_list:
|
||||
self.activate_privacy_rule('block')
|
||||
else:
|
||||
iq = self.build_privacy_rule('visible', 'allow')
|
||||
self.connection.send(iq)
|
||||
self.activate_privacy_rule('visible')
|
||||
self.set_active_list('')
|
||||
|
||||
def _update_status(self, show, msg):
|
||||
xmpp_show = helpers.get_xmpp_show(show)
|
||||
|
@ -2446,9 +2430,10 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
self.connection.send(iq)
|
||||
|
||||
def _nec_privacy_list_received(self, obj):
|
||||
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 = []
|
||||
|
@ -2475,6 +2460,12 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
self.blocked_groups.append(rule['value'])
|
||||
self.blocked_list.append(rule)
|
||||
|
||||
if 'type' in rule:
|
||||
if rule['type'] == 'jid':
|
||||
roster.draw_contact(rule['value'], self.name)
|
||||
if rule['type'] == 'group':
|
||||
roster.draw_group(rule['value'], self.name)
|
||||
|
||||
def _request_bookmarks_xml(self):
|
||||
if not gajim.account_is_connected(self.name):
|
||||
return
|
||||
|
|
|
@ -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
|
||||
|
@ -2055,6 +2061,11 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream):
|
|||
if q:
|
||||
result.delChild(q)
|
||||
self.connection.send(result)
|
||||
|
||||
for list_ in iq_obj.getQueryPayload():
|
||||
if list_.getName() == 'list':
|
||||
self.get_privacy_list(list_.getAttr('name'))
|
||||
|
||||
raise nbxmpp.NodeProcessed
|
||||
|
||||
def _getRoster(self):
|
||||
|
|
|
@ -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,14 @@ 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_default_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,18 +2797,17 @@ 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')
|
||||
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']
|
||||
else:
|
||||
connection.set_privacy_list(default, connection.new_blocked_list)
|
||||
|
||||
def on_voice_checkmenuitem_activate(self, widget, nick):
|
||||
if widget.get_active():
|
||||
|
|
Loading…
Reference in New Issue