primitivus: better chat text insertion in chat window
This commit is contained in:
parent
72da42f762
commit
7c6c829ea5
1 changed files with 19 additions and 8 deletions
|
|
@ -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<len(self.content)-2 and self.content[idx+1].message == msg:
|
||||
return
|
||||
|
||||
self.content.insert(idx+1, new_text)
|
||||
break
|
||||
else:
|
||||
self.content.append(new_text)
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue