Fix highlight navigation
This commit is contained in:
parent
01ebe78401
commit
aec4c279f2
3 changed files with 25 additions and 35 deletions
|
@ -783,6 +783,7 @@ class HandlerCore:
|
|||
# Messages coming from MUC barejid (Server maintenance, IRC mode
|
||||
# changes from biboumi, etc.) are displayed as info messages.
|
||||
if message['from'].resource:
|
||||
highlight = tab.message_is_highlight(body, nick_from, delayed)
|
||||
ui_msg = PMessage(
|
||||
txt=body,
|
||||
time=date,
|
||||
|
@ -792,6 +793,7 @@ class HandlerCore:
|
|||
identifier=message['id'],
|
||||
jid=message['from'],
|
||||
user=user,
|
||||
highlight=highlight,
|
||||
)
|
||||
typ = 1
|
||||
else:
|
||||
|
@ -801,8 +803,8 @@ class HandlerCore:
|
|||
identifier=message['id'],
|
||||
)
|
||||
typ = 2
|
||||
|
||||
if tab.add_message(ui_msg, typ):
|
||||
tab.add_message(ui_msg, typ)
|
||||
if highlight:
|
||||
self.core.events.trigger('highlight', message, tab)
|
||||
|
||||
if message['from'].resource == tab.own_nick:
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -85,7 +85,6 @@ class TextWin(Win):
|
|||
def build_new_message(self,
|
||||
message: BaseMessage,
|
||||
clean: bool = True,
|
||||
highlight: bool = False,
|
||||
timestamp: bool = False,
|
||||
nick_size: int = 10) -> int:
|
||||
"""
|
||||
|
@ -106,7 +105,7 @@ class TextWin(Win):
|
|||
self.built_lines.extend(lines)
|
||||
if not lines or not lines[0]:
|
||||
return 0
|
||||
if highlight:
|
||||
if isinstance(message, Message) and message.highlight:
|
||||
self.highlights.append(lines[0])
|
||||
self.nb_of_highlights_after_separator += 1
|
||||
log.debug("Number of highlights after separator is now %s",
|
||||
|
|
Loading…
Reference in a new issue