summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--poezio/core/handlers.py6
-rw-r--r--poezio/tabs/muctab.py51
-rw-r--r--poezio/windows/text_win.py3
3 files changed, 25 insertions, 35 deletions
diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py
index 01fb6062..445d8b74 100644
--- a/poezio/core/handlers.py
+++ b/poezio/core/handlers.py
@@ -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:
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'
diff --git a/poezio/windows/text_win.py b/poezio/windows/text_win.py
index a1b12ae9..fbe3d2fa 100644
--- a/poezio/windows/text_win.py
+++ b/poezio/windows/text_win.py
@@ -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",