# HG changeset patch # User Goffi # Date 1350816947 -7200 # Node ID 4d7248f4c577ff485b2fbfd03cec4faa775510f2 # Parent b7577230a7c81fbb2ebd869ce6b61911a314a792 primitivus: better chat text insertion in chat window diff -r b7577230a7c8 -r 4d7248f4c577 frontends/src/primitivus/chat.py --- a/frontends/src/primitivus/chat.py Sun Oct 21 12:55:27 2012 +0200 +++ b/frontends/src/primitivus/chat.py Sun Oct 21 12:55:47 2012 +0200 @@ -241,15 +241,26 @@ jid,nick,mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp) except TypeError: return - if timestamp: - for _chat_text in self.content: - if (msg == _chat_text.message and - timestamp - time.mktime(_chat_text.timestamp) < 5): - #we discard double messages, to avoid backlog / history conflict + + 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): + 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 + + #we discard double messages, to avoid backlog / history conflict + if idx and self.content[idx-1].message == msg: return - self.content.append(ChatText(self, timestamp or None, nick, mymess, msg)) - if timestamp: - self.content.sort(key=lambda chat_text: chat_text.timestamp) + if idx