Commit fa4ecfa6 authored by Philipp Hörist's avatar Philipp Hörist

Refactor sending directed presence

parent 125fe1e0
Pipeline #3679 passed with stages
in 2 minutes and 36 seconds
......@@ -1496,29 +1496,6 @@ class Connection(CommonConnection, ConnectionHandlers):
modules.send_stored_publish(self.name)
self.continue_connect_info = None
def send_custom_status(self, show, msg, jid):
if show not in app.SHOW_LIST:
return -1
if not app.account_is_connected(self.name):
return
sshow = helpers.get_xmpp_show(show)
if not msg:
msg = ''
if show == 'offline':
self.get_module('Presence').send_presence(
jid,
'unavailable',
caps=False,
status=msg)
else:
priority = app.get_priority(self.name, sshow)
self.get_module('Presence').send_presence(
jid,
priority=priority,
show=sshow,
status=msg)
def _change_to_invisible(self, msg):
self.send_invisible_presence(msg)
......
......@@ -294,7 +294,8 @@ class PrivacyLists(BaseModule):
for contact in contact_list:
self._log.info('Block contacts: %s', contact.jid)
contact.show = 'offline'
self._con.send_custom_status('offline', message, contact.jid)
self._con.get_module('Presence').send_presence(contact.jid,
typ='unavailable')
max_order = self._get_max_blocked_list_order()
new_rule = {'order': str(max_order + 1),
'type': 'jid',
......@@ -364,7 +365,8 @@ class PrivacyLists(BaseModule):
if show == 'invisible':
return
for contact in contact_list:
self._con.send_custom_status(show, self._con.status, contact.jid)
self._con.get_module('Presence').send_presence(
contact.jid, show=show, status=self._con.status)
self._presence_probe(contact.jid)
def block_group(self, group, contact_list, message):
......@@ -380,7 +382,8 @@ class PrivacyLists(BaseModule):
self.default_list = 'block'
for contact in contact_list:
self._con.send_custom_status('offline', message, contact.jid)
self._con.get_module('Presence').send_presence(
contact.jid, typ='unavailable')
max_order = self._get_max_blocked_list_order()
new_rule = {'order': str(max_order + 1),
......@@ -424,7 +427,8 @@ class PrivacyLists(BaseModule):
if show == 'invisible':
return
for contact in contact_list:
self._con.send_custom_status(show, self._con.status, contact.jid)
self._con.get_module('Presence').send_presence(
contact.jid, show=show, status=self._con.status)
def _presence_probe(self, jid):
self._log.info('Presence probe: %s', jid)
......
......@@ -2056,16 +2056,15 @@ class RosterWindow:
def set_connecting_state(self, account):
self.set_state(account, 'connecting')
def send_status(self, account, status, txt, auto=False, to=None):
def send_status(self, account, status, txt, auto=False):
if status != 'offline':
if to is None:
app.config.set_per('accounts', account, 'last_status', status)
app.config.set_per('accounts', account, 'last_status_msg',
helpers.to_one_line(txt))
app.config.set_per('accounts', account, 'last_status', status)
app.config.set_per('accounts', account, 'last_status_msg',
helpers.to_one_line(txt))
if not app.account_is_connected(account):
self.set_connecting_state(account)
self.send_status_continue(account, status, txt, auto, to)
self.send_status_continue(account, status, txt, auto)
def send_pep(self, account, pep_dict):
connection = app.connections[account]
......@@ -2098,34 +2097,30 @@ class RosterWindow:
if ctrl:
ctrl.update_all_pep_types()
def send_status_continue(self, account, status, txt, auto, to):
if app.account_is_connected(account) and not to:
def send_status_continue(self, account, status, txt, auto):
if app.account_is_connected(account):
if status == 'online' and not idle.Monitor.is_unknown():
app.sleeper_state[account] = 'online'
elif app.sleeper_state[account] not in ('autoaway', 'autoxa') or \
status == 'offline':
app.sleeper_state[account] = 'off'
if to:
app.connections[account].send_custom_status(status, txt, to)
else:
if status in ('invisible', 'offline'):
self.delete_pep(app.get_jid_from_account(account), account)
was_invisible = app.is_invisible(account)
app.connections[account].change_status(status, txt, auto)
for gc_control in app.interface.msg_win_mgr.get_controls(
message_control.TYPE_GC) + \
list(app.interface.minimized_controls[account].values()):
if gc_control.account == account:
if app.gc_connected[account][gc_control.room_jid]:
app.connections[account].get_module('MUC').send_muc_presence(
gc_control.room_jid, auto=auto)
if was_invisible and status != 'offline':
# We come back from invisible, join bookmarks
con = app.connections[account]
con.get_module('Bookmarks').auto_join_bookmarks()
if status in ('invisible', 'offline'):
self.delete_pep(app.get_jid_from_account(account), account)
was_invisible = app.is_invisible(account)
app.connections[account].change_status(status, txt, auto)
for gc_control in app.interface.msg_win_mgr.get_controls(
message_control.TYPE_GC) + \
list(app.interface.minimized_controls[account].values()):
if gc_control.account == account:
if app.gc_connected[account][gc_control.room_jid]:
app.connections[account].get_module('MUC').send_muc_presence(
gc_control.room_jid, auto=auto)
if was_invisible and status != 'offline':
# We come back from invisible, join bookmarks
con = app.connections[account]
con.get_module('Bookmarks').auto_join_bookmarks()
def chg_contact_status(self, contact, show, status, account):
"""
......
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