primitivus (chat): fixes the messages display when opening a new chat window

This commit is contained in:
souliane 2014-08-24 18:39:32 +02:00
commit 7afc9b83fa

View file

@ -297,7 +297,8 @@ class Chat(urwid.WidgetWrap, QuickChat):
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:
older = new_text.timestamp < current_text.timestamp
if older and idx > 0:
continue # the new message is older, we need to insert it upper
#we discard double messages, to avoid backlog / history conflict
@ -306,7 +307,7 @@ class Chat(urwid.WidgetWrap, QuickChat):
(idx < len(self.content) - 2 and self.content[idx + 1].message)):
return
self.content.insert(idx + 1, new_text)
self.content.insert(0 if older else idx + 1, new_text)
break
else:
self.content.append(new_text)