summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--poezio/core/handlers.py3
-rw-r--r--poezio/tabs/muctab.py35
-rw-r--r--poezio/text_buffer.py3
-rw-r--r--poezio/ui/types.py4
4 files changed, 29 insertions, 16 deletions
diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py
index cf04d582..aa392d40 100644
--- a/poezio/core/handlers.py
+++ b/poezio/core/handlers.py
@@ -766,6 +766,7 @@ class HandlerCore:
replaced_id,
message['id'],
time=delayed_date,
+ delayed=delayed,
nickname=nick_from,
user=user):
self.core.events.trigger('highlight', message, tab)
@@ -777,7 +778,7 @@ class HandlerCore:
txt=body,
time=date,
nickname=nick_from,
- history=delayed,
+ delayed=delayed,
identifier=message['id'],
jid=message['from'],
user=user,
diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py
index d1390cb5..68e0f24d 100644
--- a/poezio/tabs/muctab.py
+++ b/poezio/tabs/muctab.py
@@ -1092,7 +1092,7 @@ class MucTab(ChatTab):
msg.user.set_last_talked(msg.time)
if config.get_by_tabname('notify_messages', self.jid.bare) and self.state != 'current':
self.state = 'message'
- msg.highlight = self.do_highlight(msg.txt, msg.time, msg.nickname)
+ msg.highlight = self.do_highlight(msg.txt, msg.nickname, msg.delayed)
return msg.highlight
def modify_message(self,
@@ -1100,10 +1100,11 @@ class MucTab(ChatTab):
old_id,
new_id,
time=None,
+ delayed: bool = False,
nickname=None,
user=None,
jid=None):
- highlight = self.do_highlight(txt, time, nickname, corrected=True)
+ highlight = self.do_highlight(txt, nickname, delayed, corrected=True)
message = self._text_buffer.modify_message(
txt,
old_id,
@@ -1310,28 +1311,38 @@ 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, time, nickname, own_nick, highlight_on,
- corrected=False):
+ def is_highlight(self, txt: str, nick: str, highlight_on: List[str],
+ delayed, corrected: bool = False):
+ """
+ Highlight algorithm for MUC tabs
+ """
+
highlighted = False
- if (not time or corrected) and nickname and nickname != own_nick:
- if self.build_highlight_regex(own_nick).search(txt):
+ if not delayed and not corrected:
+ if self.build_highlight_regex(nick).search(txt):
highlighted = True
else:
- highlight_words = highlight_on.split(':')
- for word in highlight_words:
+ for word in highlight_on:
if word and word.lower() in txt.lower():
highlighted = True
break
return highlighted
- def do_highlight(self, txt, time, nickname, corrected=False):
+ 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)
- highlighted = self.is_highlight(txt, time, nickname, own_nick,
- highlight_on, corrected)
+ 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)
if highlighted and self.joined:
if self.state != 'current':
self.state = 'highlight'
diff --git a/poezio/text_buffer.py b/poezio/text_buffer.py
index 2ae51d80..3b3ac051 100644
--- a/poezio/text_buffer.py
+++ b/poezio/text_buffer.py
@@ -165,7 +165,7 @@ class TextBuffer:
raise CorrectionError('Wrong message type')
if msg.user and msg.user is not user:
raise CorrectionError("Different users")
- elif msg.history:
+ elif msg.delayed:
raise CorrectionError("Delayed message")
elif not msg.user and (msg.jid is None or jid is None):
raise CorrectionError('Could not check the '
@@ -184,7 +184,6 @@ class TextBuffer:
time=time,
nickname=msg.nickname,
nick_color=msg.nick_color,
- history=False,
user=msg.user,
identifier=orig_id,
highlight=highlight,
diff --git a/poezio/ui/types.py b/poezio/ui/types.py
index 8a36618e..ae72b6b9 100644
--- a/poezio/ui/types.py
+++ b/poezio/ui/types.py
@@ -85,7 +85,7 @@ class StatusMessage(BaseMessage):
class Message(BaseMessage):
- __slots__ = ('txt', 'nick_color', 'time', 'nickname', 'user', 'history',
+ __slots__ = ('txt', 'nick_color', 'time', 'nickname', 'user', 'delayed', 'history',
'identifier', 'top', 'highlight', 'me', 'old_message', 'revisions',
'jid', 'ack')
@@ -94,6 +94,7 @@ class Message(BaseMessage):
nickname: Optional[str],
time: Optional[datetime] = None,
nick_color: Optional[Tuple] = None,
+ delayed: bool = False,
history: bool = False,
user: Optional[User] = None,
identifier: Optional[str] = '',
@@ -120,6 +121,7 @@ class Message(BaseMessage):
else:
me = False
self.txt = txt
+ self.delayed = delayed or history
self.history = history
self.nickname = nickname
self.nick_color = nick_color