diff frontends/src/primitivus/chat.py @ 1973:a9908e751c42

quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
author Goffi <goffi@goffi.org>
date Mon, 27 Jun 2016 22:37:51 +0200
parents 9421e721d5e2
children 70e83ca721c8
line wrap: on
line diff
--- a/frontends/src/primitivus/chat.py	Mon Jun 27 22:36:22 2016 +0200
+++ b/frontends/src/primitivus/chat.py	Mon Jun 27 22:37:51 2016 +0200
@@ -133,7 +133,10 @@
             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 @@
         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)