Commit 961f6c17 authored by Maxime Buquet's avatar Maxime Buquet Committed by mathieui

Fix highlights by introducing a delayed property on ui.types.Message

Signed-off-by: Maxime Buquet's avatarMaxime “pep” Buquet <pep@bouah.net>
parent cf026cf1
......@@ -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,
......
......@@ -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'
......
......@@ -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,
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment