Skip to content
Snippets Groups Projects
Commit b2d52ad5 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Refactor auto connect

parent 0d880cb1
No related branches found
No related tags found
No related merge requests found
......@@ -269,7 +269,6 @@ class Config:
'autopriority_xa': [opt_int, 30],
'autopriority_dnd': [opt_int, 20],
'autoconnect': [opt_bool, False, '', True],
'autoconnect_as': [opt_str, 'online', _('Status to be used automatically when connecting. Can be \'online\', \'chat\', \'away\', \'xa\' or \'dnd\'. NOTE: This option is used only if \'restore_last_status\' is disabled.'), True],
'restore_last_status': [opt_bool, False, _('If enabled, the last status will be restored.')],
'autoauth': [opt_bool, False, _('If enabled, contacts requesting authorization will be accepted automatically.')],
'active': [opt_bool, True, _('If disabled, this account will be disabled and will not appear in the contact list window.'), True],
......
......@@ -1657,31 +1657,22 @@ def autoconnect(self):
"""
Auto connect at startup
"""
# dict of account that want to connect sorted by status
shows = {}
for a in app.connections:
if app.config.get_per('accounts', a, 'autoconnect'):
if app.config.get_per('accounts', a, 'restore_last_status'):
self.roster.send_status(a, app.config.get_per('accounts',
a, 'last_status'), helpers.from_one_line(
app.config.get_per('accounts', a, 'last_status_msg')))
continue
show = app.config.get_per('accounts', a, 'autoconnect_as')
if show not in ['online', 'chat', 'away', 'xa', 'dnd']:
continue
if show not in shows:
shows[show] = [a]
else:
shows[show].append(a)
def on_message(message):
if message is None:
return
for a in shows[show]:
self.roster.send_status(a, show, message)
for show in shows:
self.roster.get_status_message(show, on_message)
return False
for account in app.connections:
if not app.config.get_per('accounts', account, 'autoconnect'):
continue
status = 'online'
status_message = ''
if app.config.get_per('accounts', account, 'restore_last_status'):
status = app.config.get_per('accounts', account, 'last_status')
status_message = app.config.get_per('accounts',
account,
'last_status_msg')
status_message = helpers.from_one_line(status_message)
self.roster.send_status(account, status, status_message)
def show_systray(self):
if not app.is_display(Display.WAYLAND):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment