# HG changeset patch # User souliane # Date 1382363548 -7200 # Node ID a630b94280d527fd488fd7835f39af1d93f86dd0 # Parent 9a50aa7feefbf54cf2f4cd247a8c5c21fb8fe2c7 primitivus: code factorization for user notification diff -r 9a50aa7feefb -r a630b94280d5 frontends/src/primitivus/chat.py --- a/frontends/src/primitivus/chat.py Fri Oct 18 19:23:03 2013 +0200 +++ b/frontends/src/primitivus/chat.py Mon Oct 21 15:52:28 2013 +0200 @@ -262,60 +262,56 @@ def printMessage(self, from_jid, msg, profile, timestamp=""): assert isinstance(from_jid, JID) try: - jid,nick,mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp) + jid, nick, mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp) except TypeError: return new_text = ChatText(self, timestamp or None, nick, mymess, msg) if timestamp and self.content: - for idx in range(len(self.content)-1,-1,-1): + for idx in range(len(self.content) - 1, -1, -1): current_text = self.content[idx] if new_text.timestamp < current_text.timestamp and idx > 0: - continue #the new message is older, we need to insert it upper + continue # the new message is older, we need to insert it upper #we discard double messages, to avoid backlog / history conflict - if ((idx and self.content[idx-1].message == msg) or + if ((idx and self.content[idx - 1].message == msg) or (self.content[idx].message == msg) or - (idx "toto clenches his fist" """ - #FIXME: duplicated code, this must be refactored _widget = ChatText(self, timestamp or None, None, False, msg, is_info=True) self.content.append(_widget) - if self.text_list.get_focus()[1] == len(self.content)-2: + self._notify(msg=msg) + + def _notify(self, from_jid="somebody", msg=""): + """Notify the user of a new message if primitivus doesn't have the focus. + @param from_jid: contact who wrote to the users + @param msg: the message that has been received + """ + if self.text_list.get_focus()[1] == len(self.content) - 2: #we don't change focus if user is not at the bottom #as that mean that he is probably watching discussion history - self.text_list.set_focus(len(self.content)-1) + self.text_list.set_focus(len(self.content) - 1) self.host.redraw() if not self.host.x_notify.hasFocus(): - if self.type=="one2one": - self.host.x_notify.sendNotification(_("Primitivus: there is a message about you")) + if self.type == "one2one": + self.host.x_notify.sendNotification(_("Primitivus: %s is talking to you") % from_jid) elif self.getUserNick().lower() in msg.lower(): - self.host.x_notify.sendNotification(_("Primitivus: Somebody is talking about you in %s room") % self.target) + self.host.x_notify.sendNotification(_("Primitivus: %s mentioned you in room '%s'") % (from_jid, self.target)) def startGame(self, game_type, referee, players): """Configure the chat window to start a game"""