internal: make the MAMFiller an attribute of ChatTabs

and fetch logs in conversationtabs and privatetabs
This commit is contained in:
mathieui 2021-04-11 13:03:32 +02:00
parent f6ba263305
commit a827743b86
4 changed files with 21 additions and 7 deletions

View file

@ -45,6 +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.text_buffer import TextBuffer
from poezio.theming import get_theme, dump_tuple
from poezio.user import User
@ -511,6 +512,7 @@ class ChatTab(Tab):
message_type = 'chat'
timed_event_paused: Optional[DelayedEvent]
timed_event_not_paused: Optional[DelayedEvent]
mam_filler: Optional[MAMFiller]
def __init__(self, core, jid: Union[JID, str]):
Tab.__init__(self, core)
@ -526,6 +528,7 @@ class ChatTab(Tab):
self.directed_presence = None
self._text_buffer = TextBuffer()
self._text_buffer.add_window(self.text_win)
self.mam_filler = None
self.chatstate = None # can be "active", "composing", "paused", "gone", "inactive"
# We keep a reference of the event that will set our chatstate to "paused", so that
# we can delete it or change it if we need to
@ -967,7 +970,7 @@ class ChatTab(Tab):
if not self.query_status:
from poezio.log_loader import LogLoader
asyncio.ensure_future(
LogLoader(logger, self, config.get('use_log')).scroll_requested()
LogLoader(logger, self, config.getbool('use_log')).scroll_requested()
)
return self.text_win.scroll_up(self.text_win.height - 1)

View file

@ -11,6 +11,7 @@ There are two different instances of a ConversationTab:
the time.
"""
import asyncio
import curses
import logging
from typing import Dict, Callable
@ -20,12 +21,13 @@ 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
from poezio.decorators import refresh_wrapper
from poezio.roster import roster
from poezio.text_buffer import CorrectionError
from poezio.theming import get_theme, dump_tuple
from poezio.decorators import command_args_parser
from poezio.ui.types import InfoMessage
@ -387,6 +389,11 @@ 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

View file

@ -84,7 +84,6 @@ class MucTab(ChatTab):
plugin_keys: Dict[str, Callable[..., Any]] = {}
additional_information: Dict[str, Callable[[str], str]] = {}
lagged: bool = False
mam_filler: Optional[MAMFiller]
def __init__(self, core: Core, jid: JID, nick: str, password: Optional[str] = None) -> None:
ChatTab.__init__(self, core, jid)
@ -105,7 +104,6 @@ class MucTab(ChatTab):
self.topic_from = ''
# Self ping event, so we can cancel it when we leave the room
self.self_ping_event: Optional[timed_events.DelayedEvent] = None
self.mam_filler = None
# UI stuff
self.topic_win = windows.Topic()
self.v_separator = windows.VerticalSeparator()
@ -181,7 +179,8 @@ class MucTab(ChatTab):
seconds = None
if last_message is not None:
seconds = (datetime.now() - last_message.time).seconds
self.mam_filler = MAMFiller(self, logger)
if self.mam_filler is None and config.getbool('mam_sync'):
self.mam_filler = MAMFiller(logger, self)
muc.join_groupchat(
self.core,
self.jid.bare,

View file

@ -10,6 +10,7 @@ both participants 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,11 +25,10 @@ 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 (
BaseMessage,
InfoMessage,
Message,
PersistentInfoMessage,
)
@ -70,6 +70,11 @@ 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: