From aec4c279f27564e2e83a4f42b1c626ba50b67f95 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 17 May 2020 20:37:54 +0200 Subject: Fix highlight navigation --- poezio/tabs/muctab.py | 51 ++++++++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 31 deletions(-) (limited to 'poezio/tabs') diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index f0c055b1..02964395 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -1077,13 +1077,8 @@ class MucTab(ChatTab): return user return None - def add_message(self, msg: BaseMessage, typ=1): - """ - Note that user can be None even if nickname is not None. It happens - when we receive an history message said by someone who is not - in the room anymore - Return True if the message highlighted us. False otherwise. - """ + def add_message(self, msg: BaseMessage, typ=1) -> None: + """Add a message to the text buffer and set various tab status""" # reset self-ping interval if self.self_ping_event: self.enable_self_ping_event() @@ -1095,8 +1090,7 @@ class MucTab(ChatTab): if config.get_by_tabname('notify_messages', self.jid.bare) and self.state != 'current': if msg.nickname != self.own_nick and not msg.history: self.state = 'message' - msg.highlight = self.do_highlight(msg.txt, msg.nickname, msg.delayed) - return msg.highlight + self.do_highlight(msg.txt, msg.nickname, msg.delayed) def modify_message(self, txt, @@ -1314,15 +1308,19 @@ class MucTab(ChatTab): def build_highlight_regex(self, nickname): return re.compile(r"(^|\W)" + re.escape(nickname) + r"(\W|$)", re.I) - def is_highlight(self, txt: str, nick: str, highlight_on: List[str], - delayed, corrected: bool = False): - """ - Highlight algorithm for MUC tabs - """ - + def message_is_highlight(self, txt: str, nickname: str, delayed: bool, + corrected: bool = False) -> bool: + """Highlight algorithm for MUC tabs""" + # Don't highlight on info message or our own messages + if not nickname or nickname == self.own_nick: + return False + highlight_on = config.get_by_tabname( + 'highlight_on', + self.general_jid, + ).split(':') highlighted = False if not delayed and not corrected: - if self.build_highlight_regex(nick).search(txt): + if self.build_highlight_regex(self.own_nick).search(txt): highlighted = True else: for word in highlight_on: @@ -1331,21 +1329,12 @@ class MucTab(ChatTab): break return highlighted - def do_highlight(self, txt, nickname, delayed, corrected=False): - """ - Set the tab color and returns the nick color - """ - own_nick = self.own_nick - highlight_on = config.get_by_tabname( - 'highlight_on', - self.general_jid, - ).split(':') - - # Don't highlight on info message or our own messages - if not nickname or nickname == own_nick: - return False - - highlighted = self.is_highlight(txt, own_nick, highlight_on, delayed, corrected) + def do_highlight(self, txt: str, nickname: str, delayed: bool, + corrected: bool = False) -> bool: + """Set the tab color and returns the highlight state""" + highlighted = self.message_is_highlight( + txt, nickname, delayed, corrected + ) if highlighted and self.joined: if self.state != 'current': self.state = 'highlight' -- cgit v1.2.3