Commit cad5d0d8 authored by mathieui's avatar mathieui

WIP: update muctab.add/log message

parent 06718b6c
...@@ -1054,13 +1054,15 @@ class MucTab(ChatTab): ...@@ -1054,13 +1054,15 @@ class MucTab(ChatTab):
""" """
return self.topic.replace('\n', '|') return self.topic.replace('\n', '|')
def log_message(self, txt, nickname, time=None, typ=1): def log_message(self, msg: Message, typ=1):
""" """
Log the messages in the archives, if it needs Log the messages in the archives, if it needs
to be to be
""" """
if time is None and self.joined: # don't log the history messages if not isinstance(msg, Message):
if not logger.log_message(self.jid.bare, nickname, txt, typ=typ): return
if not msg.history and self.joined: # don't log the history messages
if not logger.log_message(self.jid.bare, msg.nickname, msg.txt, typ=typ):
self.core.information('Unable to write in the log file', self.core.information('Unable to write in the log file',
'Error') 'Error')
...@@ -1073,54 +1075,25 @@ class MucTab(ChatTab): ...@@ -1073,54 +1075,25 @@ class MucTab(ChatTab):
return user return user
return None return None
def add_message(self, txt, time=None, nickname=None, **kwargs): def add_message(self, msg: BaseMessage, typ=1):
""" """
Note that user can be None even if nickname is not None. It happens 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 when we receive an history message said by someone who is not
in the room anymore in the room anymore
Return True if the message highlighted us. False otherwise. Return True if the message highlighted us. False otherwise.
""" """
# reset self-ping interval # reset self-ping interval
if self.self_ping_event: if self.self_ping_event:
self.enable_self_ping_event() self.enable_self_ping_event()
super().add_message(msg, typ=typ)
self.log_message(txt, nickname, time=time, typ=kwargs.get('typ', 1)) if not isinstance(msg, Message):
args = dict() return
for key, value in kwargs.items(): if msg.user:
if key not in ('typ', 'forced_user'): msg.user.set_last_talked(msg.time)
args[key] = value if config.get_by_tabname('notify_messages', self.jid.bare) and self.state != 'current':
if nickname is not None: self.state = 'message'
user = self.get_user_by_name(nickname) msg.highlight = self.do_highlight(msg.txt, msg.time, msg.nickname)
else: return msg.highlight
user = None
if user:
user.set_last_talked(datetime.now())
args['user'] = user
if not user and kwargs.get('forced_user'):
args['user'] = kwargs['forced_user']
if (not time and nickname and nickname != self.own_nick
and self.state != 'current'):
if (self.state != 'highlight'
and config.get_by_tabname('notify_messages', self.jid.bare)):
self.state = 'message'
if time and not txt.startswith('/me'):
txt = '\x19%(info_col)s}%(txt)s' % {
'txt': txt,
'info_col': dump_tuple(get_theme().COLOR_LOG_MSG)
}
elif not nickname:
txt = '\x19%(info_col)s}%(txt)s' % {
'txt': txt,
'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
}
elif not kwargs.get('highlight'): # TODO
args['highlight'] = self.do_highlight(txt, time, nickname)
time = time or datetime.now()
self._text_buffer.add_message(txt, time, nickname, **args)
return args.get('highlight', False)
def modify_message(self, def modify_message(self,
txt, txt,
......
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