diff --git a/frontends/src/primitivus/chat.py b/frontends/src/primitivus/chat.py index 6960fd45..a95bccc3 100644 --- a/frontends/src/primitivus/chat.py +++ b/frontends/src/primitivus/chat.py @@ -241,15 +241,26 @@ class Chat(urwid.WidgetWrap, QuickChat): 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