From 860df5488339274f0cb50fefdd7943940ea5fc46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 8 Jul 2020 09:28:25 +0200 Subject: [PATCH] MucTab: highlight on delayed and not history MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- poezio/core/handlers.py | 11 ++++------- poezio/tabs/muctab.py | 12 +++++------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py index c344ebd3..7d46cdd0 100644 --- a/poezio/core/handlers.py +++ b/poezio/core/handlers.py @@ -427,7 +427,7 @@ class HandlerCore: time=date, nickname=remote_nick, nick_color=color, - history=delayed, + history=is_history, identifier=message['id'], jid=jid, ), @@ -761,10 +761,7 @@ class HandlerCore: old_state = tab.state delayed, date = common.find_delayed_tag(message) - - history = (tab.last_message_was_history is None and delayed) or \ - (tab.last_message_was_history and delayed) - tab.last_message_was_history = history + is_history = not tab.joined and delayed replaced = False if message.xml.find('{urn:xmpp:message-correct:0}replace') is not None: @@ -791,12 +788,12 @@ class HandlerCore: # changes from biboumi, etc.) are displayed as info messages. highlight = False if message['from'].resource: - highlight = tab.message_is_highlight(body, nick_from, delayed) + highlight = tab.message_is_highlight(body, nick_from, is_history) ui_msg = PMessage( txt=body, time=date, nickname=nick_from, - history=history, + history=is_history, delayed=delayed, identifier=message['id'], jid=message['from'], diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index 71eb3411..17bb8b3b 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -99,8 +99,6 @@ class MucTab(ChatTab): self.users = [] # type: List[User] # private conversations self.privates = [] # type: List[Tab] - # Used to check if we are still receiving muc history - self.last_message_was_history = None # type: Optional[bool] self.topic = '' self.topic_from = '' # Self ping event, so we can cancel it when we leave the room @@ -1128,7 +1126,7 @@ class MucTab(ChatTab): if msg.nickname != self.own_nick and not msg.history: self.state = 'message' if msg.txt and msg.nickname: - self.do_highlight(msg.txt, msg.nickname, msg.delayed) + self.do_highlight(msg.txt, msg.nickname, msg.history) def modify_message(self, txt: str, @@ -1348,7 +1346,7 @@ class MucTab(ChatTab): def build_highlight_regex(self, nickname: str) -> Pattern: return re.compile(r"(^|\W)" + re.escape(nickname) + r"(\W|$)", re.I) - def message_is_highlight(self, txt: str, nickname: Optional[str], delayed: bool, + def message_is_highlight(self, txt: str, nickname: Optional[str], history: bool, corrected: bool = False) -> bool: """Highlight algorithm for MUC tabs""" # Don't highlight on info message or our own messages @@ -1359,7 +1357,7 @@ class MucTab(ChatTab): self.general_jid, ).split(':') highlighted = False - if not delayed: + if not history: if self.build_highlight_regex(self.own_nick).search(txt): highlighted = True else: @@ -1369,11 +1367,11 @@ class MucTab(ChatTab): break return highlighted - def do_highlight(self, txt: str, nickname: str, delayed: bool, + def do_highlight(self, txt: str, nickname: str, history: bool, corrected: bool = False) -> bool: """Set the tab color and returns the highlight state""" highlighted = self.message_is_highlight( - txt, nickname, delayed, corrected + txt, nickname, history, corrected ) if highlighted and self.joined and not corrected: if self.state != 'current':