fix: do not triplicate messages on /message tab openings
add a synchronization primitive to avoid /say until the logs are loaded and synced (otherwise we do the /say THEN the message we just sent can be loaded from the archive, while also being displayed)
This commit is contained in:
parent
6174ca70d9
commit
def167791d
4 changed files with 14 additions and 2 deletions
|
@ -76,10 +76,17 @@ class LogLoader:
|
||||||
mam_only: bool
|
mam_only: bool
|
||||||
|
|
||||||
def __init__(self, logger: Logger, tab: tabs.ChatTab,
|
def __init__(self, logger: Logger, tab: tabs.ChatTab,
|
||||||
local_logs: bool = True):
|
local_logs: bool = True,
|
||||||
|
done_event: Optional[asyncio.Event] = None):
|
||||||
self.mam_only = not local_logs
|
self.mam_only = not local_logs
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
self.tab = tab
|
self.tab = tab
|
||||||
|
self.done_event = done_event
|
||||||
|
|
||||||
|
def _done(self) -> None:
|
||||||
|
"""Signal end if possible"""
|
||||||
|
if self.done_event is not None:
|
||||||
|
self.done_event.set()
|
||||||
|
|
||||||
async def tab_open(self) -> None:
|
async def tab_open(self) -> None:
|
||||||
"""Called on a tab opening or a MUC join"""
|
"""Called on a tab opening or a MUC join"""
|
||||||
|
@ -104,6 +111,7 @@ class LogLoader:
|
||||||
if messages:
|
if messages:
|
||||||
self.tab._text_buffer.add_history_messages(messages)
|
self.tab._text_buffer.add_history_messages(messages)
|
||||||
self.tab.core.refresh_window()
|
self.tab.core.refresh_window()
|
||||||
|
self._done()
|
||||||
|
|
||||||
async def mam_tab_open(self, nb: int) -> List[BaseMessage]:
|
async def mam_tab_open(self, nb: int) -> List[BaseMessage]:
|
||||||
"""Fetch messages in MAM when opening a new tab.
|
"""Fetch messages in MAM when opening a new tab.
|
||||||
|
@ -238,6 +246,7 @@ class LogLoader:
|
||||||
if messages:
|
if messages:
|
||||||
tab._text_buffer.add_history_messages(messages)
|
tab._text_buffer.add_history_messages(messages)
|
||||||
tab.core.refresh_window()
|
tab.core.refresh_window()
|
||||||
|
self._done()
|
||||||
|
|
||||||
async def local_scroll_requested(self, nb: int) -> List[BaseMessage]:
|
async def local_scroll_requested(self, nb: int) -> List[BaseMessage]:
|
||||||
"""Fetch messages locally on scroll up.
|
"""Fetch messages locally on scroll up.
|
||||||
|
|
|
@ -1000,6 +1000,7 @@ class OneToOneTab(ChatTab):
|
||||||
|
|
||||||
self.__status = Status("", "")
|
self.__status = Status("", "")
|
||||||
self.last_remote_message = datetime.now()
|
self.last_remote_message = datetime.now()
|
||||||
|
self._initial_log = asyncio.Event()
|
||||||
|
|
||||||
# Set to true once the first disco is done
|
# Set to true once the first disco is done
|
||||||
self.__initial_disco = False
|
self.__initial_disco = False
|
||||||
|
@ -1036,7 +1037,7 @@ class OneToOneTab(ChatTab):
|
||||||
elif use_log and initial:
|
elif use_log and initial:
|
||||||
asyncio.create_task(self.handle_message(initial, display=False))
|
asyncio.create_task(self.handle_message(initial, display=False))
|
||||||
asyncio.create_task(
|
asyncio.create_task(
|
||||||
LogLoader(logger, self, use_log).tab_open()
|
LogLoader(logger, self, use_log, self._initial_log).tab_open()
|
||||||
)
|
)
|
||||||
|
|
||||||
async def handle_message(self, msg: SMessage, display: bool = True):
|
async def handle_message(self, msg: SMessage, display: bool = True):
|
||||||
|
|
|
@ -173,6 +173,7 @@ class ConversationTab(OneToOneTab):
|
||||||
@refresh_wrapper.always
|
@refresh_wrapper.always
|
||||||
@command_args_parser.raw
|
@command_args_parser.raw
|
||||||
async def command_say(self, line: str, attention: bool = False, correct: bool = False):
|
async def command_say(self, line: str, attention: bool = False, correct: bool = False):
|
||||||
|
await self._initial_log.wait()
|
||||||
msg: SMessage = self.core.xmpp.make_message(
|
msg: SMessage = self.core.xmpp.make_message(
|
||||||
mto=self.get_dest_jid(),
|
mto=self.get_dest_jid(),
|
||||||
mfrom=self.core.xmpp.boundjid
|
mfrom=self.core.xmpp.boundjid
|
||||||
|
|
|
@ -205,6 +205,7 @@ class PrivateTab(OneToOneTab):
|
||||||
async def command_say(self, line: str, attention: bool = False, correct: bool = False) -> None:
|
async def command_say(self, line: str, attention: bool = False, correct: bool = False) -> None:
|
||||||
if not self.on:
|
if not self.on:
|
||||||
return
|
return
|
||||||
|
await self._initial_log.wait()
|
||||||
our_jid = JID(self.jid.bare)
|
our_jid = JID(self.jid.bare)
|
||||||
our_jid.resource = self.own_nick
|
our_jid.resource = self.own_nick
|
||||||
msg: SMessage = self.core.xmpp.make_message(
|
msg: SMessage = self.core.xmpp.make_message(
|
||||||
|
|
Loading…
Reference in a new issue