From 101bab502f6076049ea229d887d75d90b4a48356 Mon Sep 17 00:00:00 2001 From: mathieui Date: Thu, 10 Feb 2022 16:31:13 +0100 Subject: internal: move and split muc message handling --- poezio/core/handlers.py | 97 ++----------------------------------------------- 1 file changed, 3 insertions(+), 94 deletions(-) (limited to 'poezio/core/handlers.py') diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py index ea9fe7ac..ed21a581 100644 --- a/poezio/core/handlers.py +++ b/poezio/core/handlers.py @@ -478,7 +478,7 @@ class HandlerCore: else: contact.name = '' - async def on_groupchat_message(self, message: Message): + async def on_groupchat_message(self, message: Message) -> None: """ Triggered whenever a message is received from a multi-user chat room. """ @@ -495,99 +495,8 @@ class HandlerCore: muc.leave_groupchat( self.core.xmpp, room_from, self.core.own_nick, msg='') return - - nick_from = message['mucnick'] - user = tab.get_user_by_name(nick_from) - if user and user in tab.ignores: - return - - await self.core.events.trigger_async('muc_msg', message, tab) - use_xhtml = config.get_by_tabname('enable_xhtml_im', room_from) - tmp_dir = get_image_cache() - body = xhtml.get_body_from_message_stanza( - message, use_xhtml=use_xhtml, extract_images_to=tmp_dir) - - # TODO: #3314. Is this a MUC reflection? - # Is this an encrypted message? Is so ignore. - # It is not possible in the OMEMO case to decrypt these messages - # since we don't encrypt for our own device (something something - # forward secrecy), but even for non-FS encryption schemes anyway - # messages shouldn't have changed after a round-trip to the room. - # Otherwire replace the matching message we sent. - - if not body: - return - - old_state = tab.state - delayed, date = common.find_delayed_tag(message) - is_history = not tab.joined and delayed - - replaced = False - if message.xml.find('{urn:xmpp:message-correct:0}replace') is not None: - replaced_id = message['replace']['id'] - if replaced_id != '' and config.get_by_tabname( - 'group_corrections', message['from'].bare): - try: - delayed_date = date or datetime.now() - if tab.modify_message( - body, - replaced_id, - message['id'], - time=delayed_date, - delayed=delayed, - nickname=nick_from, - user=user): - await self.core.events.trigger_async('highlight', message, tab) - replaced = True - except CorrectionError: - log.debug('Unable to correct a message', exc_info=True) - - if not replaced: - ui_msg: Union[InfoMessage, PMessage] - # Messages coming from MUC barejid (Server maintenance, IRC mode - # changes from biboumi, etc.) are displayed as info messages. - highlight = False - if message['from'].resource: - highlight = tab.message_is_highlight(body, nick_from, is_history) - ui_msg = PMessage( - txt=body, - time=date, - nickname=nick_from, - history=is_history, - delayed=delayed, - identifier=message['id'], - jid=message['from'], - user=user, - highlight=highlight, - ) - typ = 1 - else: - ui_msg = InfoMessage( - txt=body, - time=date, - identifier=message['id'], - ) - typ = 2 - tab.add_message(ui_msg) - if highlight: - await self.core.events.trigger_async('highlight', message, tab) - - if message['from'].resource == tab.own_nick: - tab.set_last_sent_message(message, correct=replaced) - - if tab is self.core.tabs.current_tab: - tab.text_win.refresh() - tab.info_header.refresh(tab, tab.text_win, user=tab.own_user) - tab.input.refresh() - self.core.doupdate() - elif tab.state != old_state: - self.core.refresh_tab_win() - current = self.core.tabs.current_tab - if hasattr(current, 'input') and current.input: - current.input.refresh() - self.core.doupdate() - - if 'message' in config.getstr('beep_on').split(): + valid_message = await tab.handle_message(message) + if valid_message and 'message' in config.getstr('beep_on').split(): if (not config.get_by_tabname('disable_beep', room_from) and self.core.own_nick != message['from'].resource): curses.beep() -- cgit v1.2.3