Commit 6146cf6a authored by Maxime Buquet's avatar Maxime Buquet

Merge branch 'delayed-highlight' into 'master'

MucTab: don't prevent highlight on delayed only history

See merge request poezio/poezio!148
parents 73c6e833 860df548
...@@ -427,7 +427,7 @@ class HandlerCore: ...@@ -427,7 +427,7 @@ class HandlerCore:
time=date, time=date,
nickname=remote_nick, nickname=remote_nick,
nick_color=color, nick_color=color,
history=delayed, history=is_history,
identifier=message['id'], identifier=message['id'],
jid=jid, jid=jid,
), ),
...@@ -761,10 +761,7 @@ class HandlerCore: ...@@ -761,10 +761,7 @@ class HandlerCore:
old_state = tab.state old_state = tab.state
delayed, date = common.find_delayed_tag(message) delayed, date = common.find_delayed_tag(message)
is_history = not tab.joined and delayed
history = (tab.last_message_was_history is None and delayed) or \
(tab.last_message_was_history and delayed)
tab.last_message_was_history = history
replaced = False replaced = False
if message.xml.find('{urn:xmpp:message-correct:0}replace') is not None: if message.xml.find('{urn:xmpp:message-correct:0}replace') is not None:
...@@ -791,12 +788,12 @@ class HandlerCore: ...@@ -791,12 +788,12 @@ class HandlerCore:
# changes from biboumi, etc.) are displayed as info messages. # changes from biboumi, etc.) are displayed as info messages.
highlight = False highlight = False
if message['from'].resource: if message['from'].resource:
highlight = tab.message_is_highlight(body, nick_from, delayed) highlight = tab.message_is_highlight(body, nick_from, is_history)
ui_msg = PMessage( ui_msg = PMessage(
txt=body, txt=body,
time=date, time=date,
nickname=nick_from, nickname=nick_from,
history=history, history=is_history,
delayed=delayed, delayed=delayed,
identifier=message['id'], identifier=message['id'],
jid=message['from'], jid=message['from'],
......
...@@ -99,8 +99,6 @@ class MucTab(ChatTab): ...@@ -99,8 +99,6 @@ class MucTab(ChatTab):
self.users = [] # type: List[User] self.users = [] # type: List[User]
# private conversations # private conversations
self.privates = [] # type: List[Tab] self.privates = [] # type: List[Tab]
# Used to check if we are still receiving muc history
self.last_message_was_history = None # type: Optional[bool]
self.topic = '' self.topic = ''
self.topic_from = '' self.topic_from = ''
# Self ping event, so we can cancel it when we leave the room # Self ping event, so we can cancel it when we leave the room
...@@ -1128,7 +1126,7 @@ class MucTab(ChatTab): ...@@ -1128,7 +1126,7 @@ class MucTab(ChatTab):
if msg.nickname != self.own_nick and not msg.history: if msg.nickname != self.own_nick and not msg.history:
self.state = 'message' self.state = 'message'
if msg.txt and msg.nickname: if msg.txt and msg.nickname:
self.do_highlight(msg.txt, msg.nickname, msg.delayed) self.do_highlight(msg.txt, msg.nickname, msg.history)
def modify_message(self, def modify_message(self,
txt: str, txt: str,
...@@ -1348,7 +1346,7 @@ class MucTab(ChatTab): ...@@ -1348,7 +1346,7 @@ class MucTab(ChatTab):
def build_highlight_regex(self, nickname: str) -> Pattern: def build_highlight_regex(self, nickname: str) -> Pattern:
return re.compile(r"(^|\W)" + re.escape(nickname) + r"(\W|$)", re.I) return re.compile(r"(^|\W)" + re.escape(nickname) + r"(\W|$)", re.I)
def message_is_highlight(self, txt: str, nickname: Optional[str], delayed: bool, def message_is_highlight(self, txt: str, nickname: Optional[str], history: bool,
corrected: bool = False) -> bool: corrected: bool = False) -> bool:
"""Highlight algorithm for MUC tabs""" """Highlight algorithm for MUC tabs"""
# Don't highlight on info message or our own messages # Don't highlight on info message or our own messages
...@@ -1359,7 +1357,7 @@ class MucTab(ChatTab): ...@@ -1359,7 +1357,7 @@ class MucTab(ChatTab):
self.general_jid, self.general_jid,
).split(':') ).split(':')
highlighted = False highlighted = False
if not delayed: if not history:
if self.build_highlight_regex(self.own_nick).search(txt): if self.build_highlight_regex(self.own_nick).search(txt):
highlighted = True highlighted = True
else: else:
...@@ -1369,11 +1367,11 @@ class MucTab(ChatTab): ...@@ -1369,11 +1367,11 @@ class MucTab(ChatTab):
break break
return highlighted return highlighted
def do_highlight(self, txt: str, nickname: str, delayed: bool, def do_highlight(self, txt: str, nickname: str, history: bool,
corrected: bool = False) -> bool: corrected: bool = False) -> bool:
"""Set the tab color and returns the highlight state""" """Set the tab color and returns the highlight state"""
highlighted = self.message_is_highlight( highlighted = self.message_is_highlight(
txt, nickname, delayed, corrected txt, nickname, history, corrected
) )
if highlighted and self.joined and not corrected: if highlighted and self.joined and not corrected:
if self.state != 'current': if self.state != 'current':
......
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