poezio/core/handlers: Use Config from Core

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-08-31 16:13:28 +02:00
parent b56cfbafd9
commit 615120c761
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -26,7 +26,7 @@ from poezio import tabs
from poezio import xhtml
from poezio import multiuserchat as muc
from poezio.common import get_error_message
from poezio.config import config, get_image_cache
from poezio.config import get_image_cache
from poezio.core.structs import Status
from poezio.contact import Resource
from poezio.logger import logger
@ -93,7 +93,7 @@ class HandlerCore:
rostertab.check_saslexternal(features)
rostertab.check_blocking(features)
self.core.check_blocking(features)
if (config.getbool('enable_carbons')
if (self.core.config.getbool('enable_carbons')
and 'urn:xmpp:carbons:2' in features):
self.core.xmpp.plugin['xep_0280'].enable()
await self.core.check_bookmark_storage(features)
@ -219,7 +219,7 @@ class HandlerCore:
if password:
msg += ". The password is \"%s\"." % password
self.core.information(msg, 'Info')
if 'invite' in config.getstr('beep_on').split():
if 'invite' in self.core.config.getstr('beep_on').split():
curses.beep()
logger.log_roster_change(inviter.full, 'invited you to %s' % jid.full)
self.core.pending_invites[jid.bare] = inviter.full
@ -253,7 +253,7 @@ class HandlerCore:
msg += "\nreason: %s" % reason
self.core.information(msg, 'Info')
if 'invite' in config.getstr('beep_on').split():
if 'invite' in self.core.config.getstr('beep_on').split():
curses.beep()
self.core.pending_invites[room.bare] = inviter.full
@ -324,7 +324,7 @@ class HandlerCore:
return self.core.information(
'%s says: %s' % (message['from'], message['body']), 'Headline')
use_xhtml = config.get_by_tabname('enable_xhtml_im',
use_xhtml = self.core.config.get_by_tabname('enable_xhtml_im',
message['from'].bare)
tmp_dir = get_image_cache()
if not xhtml.get_body_from_message_stanza(
@ -356,8 +356,8 @@ class HandlerCore:
else:
await conversation.handle_message(message)
if not own and 'private' in config.getstr('beep_on').split():
if not config.get_by_tabname('disable_beep', conv_jid.bare):
if not own and 'private' in self.core.config.getstr('beep_on').split():
if not self.core.config.get_by_tabname('disable_beep', conv_jid.bare):
curses.beep()
if self.core.tabs.current_tab is not conversation:
if not own:
@ -487,8 +487,8 @@ class HandlerCore:
self.core.xmpp, room_from, self.core.own_nick, msg='')
return
valid_message = await tab.handle_message(message)
if valid_message and 'message' in config.getstr('beep_on').split():
if (not config.get_by_tabname('disable_beep', room_from)
if valid_message and 'message' in self.core.config.getstr('beep_on').split():
if (not self.core.config.get_by_tabname('disable_beep', room_from)
and self.core.own_nick != message['from'].resource):
curses.beep()
@ -509,7 +509,7 @@ class HandlerCore:
return
room_from = jid.bare
use_xhtml = config.get_by_tabname(
use_xhtml = self.core.config.get_by_tabname(
'enable_xhtml_im',
jid.bare
)
@ -519,10 +519,10 @@ class HandlerCore:
tab = self.core.tabs.by_name_and_class(
jid.full,
tabs.PrivateTab) # get the tab with the private conversation
ignore = config.get_by_tabname('ignore_private', room_from)
ignore = self.core.config.get_by_tabname('ignore_private', room_from)
if ignore and not sent:
await self.core.events.trigger_async('ignored_private', message, tab)
msg = config.get_by_tabname('private_auto_response', room_from)
msg = self.core.config.get_by_tabname('private_auto_response', room_from)
if msg and body:
self.core.xmpp.send_message(
mto=jid.full, mbody=msg, mtype='chat')
@ -540,8 +540,8 @@ class HandlerCore:
else:
await tab.handle_message(message)
if not sent and 'private' in config.getstr('beep_on').split():
if not config.get_by_tabname('disable_beep', jid.full):
if not sent and 'private' in self.core.config.getstr('beep_on').split():
if not self.core.config.get_by_tabname('disable_beep', jid.full):
curses.beep()
if tab is self.core.tabs.current_tab:
self.core.refresh_window()
@ -589,7 +589,8 @@ class HandlerCore:
tab.refresh_info_header()
self.core.doupdate()
else:
_composing_tab_state(tab, state)
show = self.core.config.getstr('show_composing_tabs')
_composing_tab_state(tab, state, show)
self.core.refresh_tab_win()
return True
@ -607,7 +608,8 @@ class HandlerCore:
tab.refresh_info_header()
self.core.doupdate()
else:
_composing_tab_state(tab, state)
show = self.core.config.getstr('show_composing_tabs')
_composing_tab_state(tab, state, show)
self.core.refresh_tab_win()
async def on_chatstate_groupchat_conversation(self, message: Message, state: str):
@ -626,7 +628,8 @@ class HandlerCore:
tab.input.refresh()
self.core.doupdate()
else:
_composing_tab_state(tab, state)
show = self.core.config.getstr('show_composing_tabs')
_composing_tab_state(tab, state, show)
self.core.refresh_tab_win()
@staticmethod
@ -904,13 +907,13 @@ class HandlerCore:
"""
When we are disconnected from remote server
"""
if 'disconnect' in config.getstr('beep_on').split():
if 'disconnect' in self.core.config.getstr('beep_on').split():
curses.beep()
# Stop the ping plugin. It would try to send stanza on regular basis
self.core.xmpp.plugin['xep_0199'].disable_keepalive()
msg_typ = 'Error' if not self.core.legitimate_disconnect else 'Info'
self.core.information("Disconnected from server%s." % (event and ": %s" % event or ""), msg_typ)
if self.core.legitimate_disconnect or not config.getbool(
if self.core.legitimate_disconnect or not self.core.config.getbool(
'auto_reconnect'):
return
if (self.core.last_stream_error
@ -975,7 +978,7 @@ class HandlerCore:
self.core.xmpp.get_roster()
roster.update_contact_groups(self.core.xmpp.boundjid.bare)
# send initial presence
if config.getbool('send_initial_presence'):
if self.core.config.getbool('send_initial_presence'):
pres = self.core.xmpp.make_presence()
pres['show'] = self.core.status.show
pres['status'] = self.core.status.message
@ -985,7 +988,7 @@ class HandlerCore:
# join all the available bookmarks. As of yet, this is just the local ones
self.core.join_initial_rooms(self.core.bookmarks.local())
if config.getbool('enable_user_nick'):
if self.core.config.getbool('enable_user_nick'):
self.core.xmpp.plugin['xep_0172'].publish_nick(
nick=self.core.own_nick, callback=dumb_callback)
asyncio.create_task(self.core.xmpp.plugin['xep_0115'].update_caps())
@ -1243,7 +1246,7 @@ class HandlerCore:
'New certificate accepted:\nnew: %s\nold: %s' %
(old_cert, new_cert), 'Info')
log.debug('Setting certificate to %s', new_cert)
if not config.silent_set('certificate', new_cert):
if not self.core.config.silent_set('certificate', new_cert):
self.core.information('Unable to write in the config file',
'Error')
else:
@ -1278,14 +1281,14 @@ class HandlerCore:
"""
Check the server certificate using the slixmpp ssl_cert event
"""
if config.getbool('ignore_certificate'):
if self.core.config.getbool('ignore_certificate'):
return
cert = config.getstr('certificate')
cert = self.core.config.getstr('certificate')
# update the cert representation when it uses the old one
if cert and ':' not in cert:
cert = ':'.join(
i + j for i, j in zip(cert[::2], cert[1::2])).upper()
config.set_and_save('certificate', cert)
self.core.config.set_and_save('certificate', cert)
der = ssl.PEM_cert_to_DER_cert(pem)
asn1 = pyasn1.codec.der.decoder.decode(
@ -1306,7 +1309,7 @@ class HandlerCore:
log.debug(
'Current hash is cert hash, moving to SPKI hash (%s)',
spki_found_cert)
config.set_and_save('certificate', spki_found_cert)
self.core.config.set_and_save('certificate', spki_found_cert)
return
elif spki_found_cert == cert:
return
@ -1314,7 +1317,7 @@ class HandlerCore:
self._ssl_pop_tab(cert, spki_found_cert)
else:
log.debug('First time. Setting certificate to %s', spki_found_cert)
if not config.silent_set('certificate', spki_found_cert):
if not self.core.config.silent_set('certificate', spki_found_cert):
self.core.information('Unable to write in the config file',
'Error')
@ -1408,7 +1411,7 @@ class HandlerCore:
self.core.close_tab()
def _composing_tab_state(tab, state):
def _composing_tab_state(tab, state, show_composing_tabs):
"""
Set a tab state to or from the "composing" state
according to the config and the current tab state
@ -1422,8 +1425,7 @@ def _composing_tab_state(tab, state):
else:
return # should not happen
show = config.getstr('show_composing_tabs').lower()
show = show in values
show = show_composing_tabs.lower() in values
if tab.state != 'composing' and state == 'composing':
if show: