comparison 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
comparison
equal deleted inserted replaced
1972:02d21a589be2 1973:a9908e751c42
131 131
132 if self.selected_lang: 132 if self.selected_lang:
133 markup.append(("msg_lang", u"[{}] ".format(self.selected_lang))) 133 markup.append(("msg_lang", u"[{}] ".format(self.selected_lang)))
134 134
135 # message body 135 # message body
136 markup.append(msg) 136 if d.mention:
137 markup.append(("msg_mention", msg))
138 else:
139 markup.append(msg)
137 140
138 return markup 141 return markup
139 142
140 @total_ordering 143 @total_ordering
141 class OccupantWidget(urwid.WidgetWrap): 144 class OccupantWidget(urwid.WidgetWrap):
389 self.focus_marker_set = False 392 self.focus_marker_set = False
390 393
391 if not message.message: 394 if not message.message:
392 log.error(u"Received an empty message for uid {}".format(message.uid)) 395 log.error(u"Received an empty message for uid {}".format(message.uid))
393 else: 396 else:
394 self.mess_walker.append(MessageWidget(message)) 397 wid = MessageWidget(message)
398 self.mess_walker.append(wid)
395 self.mess_widgets.focus_position = len(self.mess_walker) - 1 # scroll down 399 self.mess_widgets.focus_position = len(self.mess_walker) - 1 # scroll down
396 self.host.redraw() # FIXME: should not be necessary 400 self.host.redraw() # FIXME: should not be necessary
401 if wid.mess_data.mention:
402 from_jid = wid.mess_data.from_jid
403 msg = _(u'You have been mentioned by {nick} in {room}'.format(
404 nick=wid.mess_data.nick,
405 room=self.target,
406 ))
407 self.host.notify(C.NOTIFY_MENTION, from_jid, msg, widget=self, profile=self.profile)
408 elif self.type == C.CHAT_ONE2ONE:
409 from_jid = wid.mess_data.from_jid
410 msg = _(u'{entity} is talking to you'.format(
411 entity=from_jid,
412 ))
413 self.host.notify(C.NOTIFY_MESSAGE, from_jid, msg, widget=self, profile=self.profile)
397 414
398 def addUser(self, nick): 415 def addUser(self, nick):
399 occupant = super(Chat, self).addUser(nick) 416 occupant = super(Chat, self).addUser(nick)
400 bisect.insort(self.occupants_walker, OccupantWidget(occupant)) 417 bisect.insort(self.occupants_walker, OccupantWidget(occupant))
401 418