From 2b76f72e4d58eb540aa19173a050142f5199ff81 Mon Sep 17 00:00:00 2001 From: mathieui Date: Tue, 22 Jun 2021 23:16:42 +0200 Subject: Fix the message doubling situation Add an "initial" parameter for onetoonetabs, and delay the reception of the message until the sync is done (and possibly ignore the message if it is fetched by the sync). Fixes #3542 --- poezio/tabs/basetabs.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'poezio/tabs/basetabs.py') diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index 43ab237f..f52122a5 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -999,7 +999,7 @@ class ChatTab(Tab): class OneToOneTab(ChatTab): - def __init__(self, core, jid): + def __init__(self, core, jid, initial=None): ChatTab.__init__(self, core, jid) self.__status = Status("", "") @@ -1018,18 +1018,29 @@ 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() + self.init_logs(initial=initial) - def init_logs(self) -> None: + def init_logs(self, initial=None) -> 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: limit = config.get_by_tabname('mam_sync_limit', self.jid) self.mam_filler = MAMFiller(logger, self, limit) + + async def fallback_no_mam(): + await self.mam_filler.done.wait() + if self.mam_filler.result == 0: + self.handle_message(initial) + asyncio.ensure_future(fallback_no_mam()) + elif use_log and initial: + self.handle_message(initial, display=False) asyncio.ensure_future( LogLoader(logger, self, use_log).tab_open() ) + def handle_message(self, msg: SMessage, display: bool = True): + pass + def remote_user_color(self): return dump_tuple(get_theme().COLOR_REMOTE_USER) -- cgit v1.2.3