internal: make mam_sync and use_log use tab-specific options

This commit is contained in:
mathieui 2021-04-11 13:31:20 +02:00
parent 6f36d6b507
commit 4ae1b714c4
4 changed files with 21 additions and 21 deletions

View file

@ -45,7 +45,7 @@ from poezio.core.structs import Command, Completion, Status
from poezio.config import config from poezio.config import config
from poezio.decorators import command_args_parser, refresh_wrapper from poezio.decorators import command_args_parser, refresh_wrapper
from poezio.logger import logger 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.text_buffer import TextBuffer
from poezio.theming import get_theme, dump_tuple from poezio.theming import get_theme, dump_tuple
from poezio.user import User from poezio.user import User
@ -1008,6 +1008,16 @@ class OneToOneTab(ChatTab):
shortdesc='Request the attention.', shortdesc='Request the attention.',
desc='Attention: Request the attention of the contact. Can also ' desc='Attention: Request the attention of the contact. Can also '
'send a message along with the attention.') '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): def remote_user_color(self):
return dump_tuple(get_theme().COLOR_REMOTE_USER) return dump_tuple(get_theme().COLOR_REMOTE_USER)

View file

@ -21,8 +21,6 @@ from poezio.tabs.basetabs import OneToOneTab, Tab
from poezio import common from poezio import common
from poezio import windows from poezio import windows
from poezio import xhtml from poezio import xhtml
from poezio.log_loader import MAMFiller, LogLoader
from poezio.logger import logger
from poezio.common import safeJID from poezio.common import safeJID
from poezio.config import config from poezio.config import config
from poezio.core.structs import Command from poezio.core.structs import Command
@ -389,11 +387,6 @@ class DynamicConversationTab(ConversationTab):
self.resize() self.resize()
self.update_commands() self.update_commands()
self.update_keys() 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): def get_info_header(self):
return self.info_header return self.info_header
@ -462,5 +455,9 @@ class StaticConversationTab(ConversationTab):
self.update_commands() self.update_commands()
self.update_keys() self.update_keys()
def init_logs(self) -> None:
# Disable local logs because…
pass
def get_info_header(self): def get_info_header(self):
return self.info_header return self.info_header

View file

@ -59,7 +59,6 @@ from poezio.ui.types import (
Message, Message,
MucOwnJoinMessage, MucOwnJoinMessage,
MucOwnLeaveMessage, MucOwnLeaveMessage,
StatusMessage,
PersistentInfoMessage, PersistentInfoMessage,
) )
@ -179,7 +178,9 @@ class MucTab(ChatTab):
seconds = None seconds = None
if last_message is not None: if last_message is not None:
seconds = (datetime.now() - last_message.time).seconds 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) self.mam_filler = MAMFiller(logger, self)
muc.join_groupchat( muc.join_groupchat(
self.core, self.core,
@ -606,9 +607,9 @@ class MucTab(ChatTab):
}, },
), ),
) )
asyncio.ensure_future( asyncio.ensure_future(LogLoader(
LogLoader(logger, self, config.get('use_log')).tab_open(), 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: def handle_presence_joined(self, presence: Presence, status_codes: Set[int]) -> None:
""" """

View file

@ -10,7 +10,6 @@ both participants nicks. It also has slightly different features than
the ConversationTab (such as tab-completion on nicks from the room). the ConversationTab (such as tab-completion on nicks from the room).
""" """
import asyncio
import curses import curses
import logging import logging
from typing import Dict, Callable from typing import Dict, Callable
@ -24,8 +23,6 @@ from poezio import xhtml
from poezio.config import config from poezio.config import config
from poezio.core.structs import Command from poezio.core.structs import Command
from poezio.decorators import refresh_wrapper 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.theming import get_theme, dump_tuple
from poezio.decorators import command_args_parser from poezio.decorators import command_args_parser
from poezio.ui.types import ( from poezio.ui.types import (
@ -70,11 +67,6 @@ class PrivateTab(OneToOneTab):
self.on = True self.on = True
self.update_commands() self.update_commands()
self.update_keys() 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 @property
def log_name(self) -> str: def log_name(self) -> str: