quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)

This commit is contained in:
Goffi 2016-06-27 22:37:51 +02:00
commit aace5a2520
4 changed files with 37 additions and 2 deletions

View file

@ -133,7 +133,10 @@ class MessageWidget(urwid.WidgetWrap):
markup.append(("msg_lang", u"[{}] ".format(self.selected_lang)))
# message body
markup.append(msg)
if d.mention:
markup.append(("msg_mention", msg))
else:
markup.append(msg)
return markup
@ -391,9 +394,23 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
if not message.message:
log.error(u"Received an empty message for uid {}".format(message.uid))
else:
self.mess_walker.append(MessageWidget(message))
wid = MessageWidget(message)
self.mess_walker.append(wid)
self.mess_widgets.focus_position = len(self.mess_walker) - 1 # scroll down
self.host.redraw() # FIXME: should not be necessary
if wid.mess_data.mention:
from_jid = wid.mess_data.from_jid
msg = _(u'You have been mentioned by {nick} in {room}'.format(
nick=wid.mess_data.nick,
room=self.target,
))
self.host.notify(C.NOTIFY_MENTION, from_jid, msg, widget=self, profile=self.profile)
elif self.type == C.CHAT_ONE2ONE:
from_jid = wid.mess_data.from_jid
msg = _(u'{entity} is talking to you'.format(
entity=from_jid,
))
self.host.notify(C.NOTIFY_MESSAGE, from_jid, msg, widget=self, profile=self.profile)
def addUser(self, nick):
occupant = super(Chat, self).addUser(nick)

View file

@ -33,12 +33,15 @@ class Const(constants.Const):
('default_focus', 'default,bold', 'default'),
('cl_notifs', 'default,underline', 'yellow'),
('cl_notifs_focus', 'default,bold,underline', 'yellow'),
('cl_mention', 'dark red', 'default'),
('cl_mention_focus', 'dark red,bold', 'default'),
# Messages
('date', 'light gray', 'default'),
('my_nick', 'dark red,bold', 'default'),
('other_nick', 'dark cyan,bold', 'default'),
('info_msg', 'yellow', 'default', 'bold'),
('msg_lang', 'dark cyan', 'default'),
('msg_mention', 'dark red, bold', 'default'),
('menubar', 'light gray,bold', 'dark red'),
('menubar_focus', 'light gray,bold', 'dark green'),

View file

@ -201,6 +201,8 @@ class ContactList(PrimitivusWidget, QuickContactList):
if notifs:
entity_attr = 'cl_notifs'
header = u'({}) '.format(len(notifs))
if self.host.getNotifs(entity.bare, C.NOTIFY_MENTION, profile=self.profile):
header = ('cl_mention', header)
else:
header = u''

View file

@ -57,6 +57,12 @@ class Message(object):
self.nick = self.getNick(from_jid)
# own_mess is True if message was sent by profile's jid
self.own_mess = (from_jid.resource == self.parent.nick) if self.parent.type == C.CHAT_GROUP else (from_jid.bare == self.host.profiles[profile].whoami.bare)
# is user mentioned here ?
if self.parent.type == C.CHAT_GROUP and not self.own_mess:
for m in msg.itervalues():
if self.parent.nick.lower() in m.lower():
self._mention = True
break
self.widgets = set() # widgets linked to this message
@property
@ -67,6 +73,13 @@ class Message(object):
def info_type(self):
return self.extra.get('info_type')
@property
def mention(self):
try:
return self._mention
except AttributeError:
return False
def getNick(self, entity):
"""Return nick of an entity when possible"""
contact_list = self.host.contact_lists[self.profile]