abilty to do some exceptions to invisible rule (to send custom status). Fixes #4631
This commit is contained in:
parent
d9277816c7
commit
6080bea672
|
@ -856,14 +856,39 @@ class Connection(ConnectionHandlers):
|
||||||
return
|
return
|
||||||
common.xmpp.features_nb.setDefaultPrivacyList(self.connection, listname)
|
common.xmpp.features_nb.setDefaultPrivacyList(self.connection, listname)
|
||||||
|
|
||||||
def build_privacy_rule(self, name, action):
|
def build_privacy_rule(self, name, action, order=1):
|
||||||
'''Build a Privacy rule stanza for invisibility'''
|
'''Build a Privacy rule stanza for invisibility'''
|
||||||
iq = common.xmpp.Iq('set', common.xmpp.NS_PRIVACY, xmlns = '')
|
iq = common.xmpp.Iq('set', common.xmpp.NS_PRIVACY, xmlns = '')
|
||||||
l = iq.getTag('query').setTag('list', {'name': name})
|
l = iq.getTag('query').setTag('list', {'name': name})
|
||||||
i = l.setTag('item', {'action': action, 'order': '1'})
|
i = l.setTag('item', {'action': action, 'order': str(order)})
|
||||||
i.setTag('presence-out')
|
i.setTag('presence-out')
|
||||||
return iq
|
return iq
|
||||||
|
|
||||||
|
def build_invisible_rule(self):
|
||||||
|
iq = common.xmpp.Iq('set', common.xmpp.NS_PRIVACY, xmlns = '')
|
||||||
|
l = iq.getTag('query').setTag('list', {'name': 'invisible'})
|
||||||
|
if self.name in gajim.interface.status_sent_to_groups and \
|
||||||
|
len(gajim.interface.status_sent_to_groups[self.name]) > 0:
|
||||||
|
for group in gajim.interface.status_sent_to_groups[self.name]:
|
||||||
|
i = l.setTag('item', {'type': 'group', 'value': group,
|
||||||
|
'action': 'allow', 'order': '1'})
|
||||||
|
i.setTag('presence-out')
|
||||||
|
if self.name in gajim.interface.status_sent_to_users and \
|
||||||
|
len(gajim.interface.status_sent_to_users[self.name]) > 0:
|
||||||
|
for jid in gajim.interface.status_sent_to_users[self.name]:
|
||||||
|
i = l.setTag('item', {'type': 'jid', 'value': jid,
|
||||||
|
'action': 'allow', 'order': '2'})
|
||||||
|
i.setTag('presence-out')
|
||||||
|
i = l.setTag('item', {'action': 'deny', 'order': '3'})
|
||||||
|
i.setTag('presence-out')
|
||||||
|
return iq
|
||||||
|
|
||||||
|
def set_invisible_rule(self):
|
||||||
|
if not gajim.account_is_connected(self.name):
|
||||||
|
return
|
||||||
|
iq = self.build_invisible_rule()
|
||||||
|
self.connection.send(iq)
|
||||||
|
|
||||||
def activate_privacy_rule(self, name):
|
def activate_privacy_rule(self, name):
|
||||||
'''activate a privacy rule'''
|
'''activate a privacy rule'''
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
|
@ -892,7 +917,7 @@ class Connection(ConnectionHandlers):
|
||||||
self.connection.send(p)
|
self.connection.send(p)
|
||||||
|
|
||||||
# try to set the privacy rule
|
# try to set the privacy rule
|
||||||
iq = self.build_privacy_rule('invisible', 'deny')
|
iq = self.build_invisible_rule()
|
||||||
self.connection.SendAndCallForResponse(iq, self._continue_invisible,
|
self.connection.SendAndCallForResponse(iq, self._continue_invisible,
|
||||||
{'msg': msg, 'signed': signed, 'initial': initial})
|
{'msg': msg, 'signed': signed, 'initial': initial})
|
||||||
|
|
||||||
|
|
|
@ -3150,24 +3150,40 @@ class RosterWindow:
|
||||||
|
|
||||||
def on_send_custom_status(self, widget, contact_list, show, group=None):
|
def on_send_custom_status(self, widget, contact_list, show, group=None):
|
||||||
'''send custom status'''
|
'''send custom status'''
|
||||||
|
# contact_list has only one element except if group != None
|
||||||
def on_response(message):
|
def on_response(message):
|
||||||
if message is None: # None if user pressed Cancel
|
if message is None: # None if user pressed Cancel
|
||||||
return
|
return
|
||||||
|
account_list = []
|
||||||
for (contact, account) in contact_list:
|
for (contact, account) in contact_list:
|
||||||
our_jid = gajim.get_jid_from_account(account)
|
if account not in account_list:
|
||||||
accounts = []
|
account_list.append(account)
|
||||||
if group and account not in accounts:
|
# 1. update status_sent_to_[groups|users] list
|
||||||
|
if group:
|
||||||
|
for account in account_list:
|
||||||
if account not in gajim.interface.status_sent_to_groups:
|
if account not in gajim.interface.status_sent_to_groups:
|
||||||
gajim.interface.status_sent_to_groups[account] = {}
|
gajim.interface.status_sent_to_groups[account] = {}
|
||||||
gajim.interface.status_sent_to_groups[account][group] = show
|
gajim.interface.status_sent_to_groups[account][group] = show
|
||||||
accounts.append(group)
|
else:
|
||||||
|
for (contact, account) in contact_list:
|
||||||
|
if account not in gajim.interface.status_sent_to_users:
|
||||||
|
gajim.interface.status_sent_to_users[account] = {}
|
||||||
|
gajim.interface.status_sent_to_users[account][contact.jid] = show
|
||||||
|
|
||||||
|
# 2. update privacy lists if main status is invisible
|
||||||
|
for account in account_list:
|
||||||
|
if gajim.SHOW_LIST[gajim.connections[account].connected] == \
|
||||||
|
'invisible':
|
||||||
|
gajim.connections[account].set_invisible_rule()
|
||||||
|
|
||||||
|
# 3. send directed presence
|
||||||
|
for (contact, account) in contact_list:
|
||||||
|
our_jid = gajim.get_jid_from_account(account)
|
||||||
jid = contact.jid
|
jid = contact.jid
|
||||||
if jid == our_jid:
|
if jid == our_jid:
|
||||||
jid += '/' + contact.resource
|
jid += '/' + contact.resource
|
||||||
self.send_status(account, show, message, to=jid)
|
self.send_status(account, show, message, to=jid)
|
||||||
if account not in gajim.interface.status_sent_to_users:
|
|
||||||
gajim.interface.status_sent_to_users[account] = {}
|
|
||||||
gajim.interface.status_sent_to_users[account][contact.jid] = show
|
|
||||||
dialogs.ChangeStatusMessageDialog(on_response, show)
|
dialogs.ChangeStatusMessageDialog(on_response, show)
|
||||||
|
|
||||||
def on_status_combobox_changed(self, widget):
|
def on_status_combobox_changed(self, widget):
|
||||||
|
|
Loading…
Reference in New Issue