From 4ae1b714c47440419c56f2fdce288bd6350348e2 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 11 Apr 2021 13:31:20 +0200 Subject: internal: make mam_sync and use_log use tab-specific options --- poezio/tabs/basetabs.py | 12 +++++++++++- poezio/tabs/conversationtab.py | 11 ++++------- poezio/tabs/muctab.py | 11 ++++++----- poezio/tabs/privatetab.py | 8 -------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index d7dac0e0..34b2efdc 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -45,7 +45,7 @@ from poezio.core.structs import Command, Completion, Status from poezio.config import config from poezio.decorators import command_args_parser, refresh_wrapper from poezio.logger import logger -from poezio.log_loader import MAMFiller +from poezio.log_loader import MAMFiller, LogLoader from poezio.text_buffer import TextBuffer from poezio.theming import get_theme, dump_tuple from poezio.user import User @@ -1008,6 +1008,16 @@ class OneToOneTab(ChatTab): shortdesc='Request the attention.', desc='Attention: Request the attention of the contact. Can also ' 'send a message along with the attention.') + self.init_logs() + + def init_logs(self) -> None: + use_log = config.get_by_tabname('use_log', self.jid) + mam_sync = config.get_by_tabname('mam_sync', self.jid) + if use_log and mam_sync: + self.mam_filler = MAMFiller(logger, self) + asyncio.ensure_future( + LogLoader(logger, self, use_log).tab_open() + ) def remote_user_color(self): return dump_tuple(get_theme().COLOR_REMOTE_USER) diff --git a/poezio/tabs/conversationtab.py b/poezio/tabs/conversationtab.py index 8b06c5fc..2cc6aa2f 100644 --- a/poezio/tabs/conversationtab.py +++ b/poezio/tabs/conversationtab.py @@ -21,8 +21,6 @@ from poezio.tabs.basetabs import OneToOneTab, Tab from poezio import common from poezio import windows from poezio import xhtml -from poezio.log_loader import MAMFiller, LogLoader -from poezio.logger import logger from poezio.common import safeJID from poezio.config import config from poezio.core.structs import Command @@ -389,11 +387,6 @@ class DynamicConversationTab(ConversationTab): self.resize() self.update_commands() self.update_keys() - if config.getbool('mam_sync'): - self.mam_filler = MAMFiller(logger, self) - asyncio.ensure_future( - LogLoader(logger, self, config.getbool('use_log')).tab_open() - ) def get_info_header(self): return self.info_header @@ -462,5 +455,9 @@ class StaticConversationTab(ConversationTab): self.update_commands() self.update_keys() + def init_logs(self) -> None: + # Disable local logs because… + pass + def get_info_header(self): return self.info_header diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index 593be6ce..c48ccebc 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -59,7 +59,6 @@ from poezio.ui.types import ( Message, MucOwnJoinMessage, MucOwnLeaveMessage, - StatusMessage, PersistentInfoMessage, ) @@ -179,7 +178,9 @@ class MucTab(ChatTab): seconds = None if last_message is not None: seconds = (datetime.now() - last_message.time).seconds - if self.mam_filler is None and config.getbool('mam_sync'): + use_log = config.get_by_tabname('mam_sync', self.general_jid) + mam_sync = config.get_by_tabname('mam_sync', self.general_jid) + if self.mam_filler is None and use_log and mam_sync: self.mam_filler = MAMFiller(logger, self) muc.join_groupchat( self.core, @@ -606,9 +607,9 @@ class MucTab(ChatTab): }, ), ) - asyncio.ensure_future( - LogLoader(logger, self, config.get('use_log')).tab_open(), - ) + asyncio.ensure_future(LogLoader( + logger, self, config.get_by_tabname('use_log', self.general_jid) + ).tab_open()) def handle_presence_joined(self, presence: Presence, status_codes: Set[int]) -> None: """ diff --git a/poezio/tabs/privatetab.py b/poezio/tabs/privatetab.py index 2d4a73e1..e24b5521 100644 --- a/poezio/tabs/privatetab.py +++ b/poezio/tabs/privatetab.py @@ -10,7 +10,6 @@ both participant’s nicks. It also has slightly different features than the ConversationTab (such as tab-completion on nicks from the room). """ -import asyncio import curses import logging from typing import Dict, Callable @@ -24,8 +23,6 @@ from poezio import xhtml from poezio.config import config from poezio.core.structs import Command from poezio.decorators import refresh_wrapper -from poezio.logger import logger -from poezio.log_loader import LogLoader, MAMFiller from poezio.theming import get_theme, dump_tuple from poezio.decorators import command_args_parser from poezio.ui.types import ( @@ -70,11 +67,6 @@ class PrivateTab(OneToOneTab): self.on = True self.update_commands() self.update_keys() - if config.getbool('mam_sync'): - self.mam_filler = MAMFiller(logger, self) - asyncio.ensure_future( - LogLoader(logger, self, config.getbool('use_log')).tab_open() - ) @property def log_name(self) -> str: -- cgit v1.2.3