From 456c4c46a6a740063e25ffcdd6cbdfeb70e4d621 Mon Sep 17 00:00:00 2001 From: mathieui Date: Thu, 10 Feb 2022 18:27:05 +0100 Subject: internal: make the other message handlers async --- poezio/core/handlers.py | 4 ++-- poezio/tabs/basetabs.py | 10 +++++----- poezio/tabs/conversationtab.py | 4 ++-- poezio/tabs/privatetab.py | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py index ed21a581..5b80585f 100644 --- a/poezio/core/handlers.py +++ b/poezio/core/handlers.py @@ -363,7 +363,7 @@ class HandlerCore: ) self.core.tabs.append(conversation) else: - conversation.handle_message(message) + await conversation.handle_message(message) if not own and 'private' in config.getstr('beep_on').split(): if not config.get_by_tabname('disable_beep', conv_jid.bare): @@ -547,7 +547,7 @@ class HandlerCore: self.core.tabs.append(tab) tab.parent_muc.privates.append(tab) else: - tab.handle_message(message) + await tab.handle_message(message) if not sent and 'private' in config.getstr('beep_on').split(): if not config.get_by_tabname('disable_beep', jid.full): diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index c2d9e93e..83e8049c 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -1020,7 +1020,7 @@ class OneToOneTab(ChatTab): 'send a message along with the attention.') self.init_logs(initial=initial) - def init_logs(self, initial=None) -> None: + def init_logs(self, initial: Optional[SMessage] = 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: @@ -1031,19 +1031,19 @@ class OneToOneTab(ChatTab): if initial is not None: # If there is an initial message, throw it back into the # text buffer if it cannot be fetched from mam - async def fallback_no_mam(): + async def fallback_no_mam() -> None: await mam_filler.done.wait() if mam_filler.result == 0: - self.handle_message(initial) + await self.handle_message(initial) asyncio.create_task(fallback_no_mam()) elif use_log and initial: - self.handle_message(initial, display=False) + asyncio.create_task(self.handle_message(initial, display=False)) asyncio.create_task( LogLoader(logger, self, use_log).tab_open() ) - def handle_message(self, msg: SMessage, display: bool = True): + async def handle_message(self, msg: SMessage, display: bool = True): pass def remote_user_color(self): diff --git a/poezio/tabs/conversationtab.py b/poezio/tabs/conversationtab.py index b95dff98..a7c019e4 100644 --- a/poezio/tabs/conversationtab.py +++ b/poezio/tabs/conversationtab.py @@ -106,7 +106,7 @@ class ConversationTab(OneToOneTab): def completion(self): self.complete_commands(self.input) - def handle_message(self, message: SMessage, display: bool = True): + async def handle_message(self, message: SMessage, display: bool = True): """Handle a received message. The message can come from us (carbon copy). @@ -133,7 +133,7 @@ class ConversationTab(OneToOneTab): else: return - self.core.events.trigger('conversation_msg', message, self) + await self.core.events.trigger_async('conversation_msg', message, self) if not message['body']: return diff --git a/poezio/tabs/privatetab.py b/poezio/tabs/privatetab.py index bb9c6538..25f50a49 100644 --- a/poezio/tabs/privatetab.py +++ b/poezio/tabs/privatetab.py @@ -142,7 +142,7 @@ class PrivateTab(OneToOneTab): and not self.input.get_text().startswith('//')) self.send_composing_chat_state(empty_after) - def handle_message(self, message: SMessage, display: bool = True): + async def handle_message(self, message: SMessage, display: bool = True): sent = message['from'].bare == self.core.xmpp.boundjid.bare jid = message['to'] if sent else message['from'] with_nick = jid.resource @@ -156,7 +156,7 @@ class PrivateTab(OneToOneTab): ) tmp_dir = get_image_cache() if not sent: - self.core.events.trigger('private_msg', message, self) + await self.core.events.trigger_async('private_msg', message, self) body = xhtml.get_body_from_message_stanza( message, use_xhtml=use_xhtml, extract_images_to=tmp_dir) if not body or not self: -- cgit v1.2.3