comparison frontends/src/primitivus/chat.py @ 520:4d7248f4c577

primitivus: better chat text insertion in chat window
author Goffi <goffi@goffi.org>
date Sun, 21 Oct 2012 12:55:47 +0200
parents 75216d94a89d
children 3f8c2a0f20e5
comparison
equal deleted inserted replaced
519:b7577230a7c8 520:4d7248f4c577
239 assert isinstance(from_jid, JID) 239 assert isinstance(from_jid, JID)
240 try: 240 try:
241 jid,nick,mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp) 241 jid,nick,mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp)
242 except TypeError: 242 except TypeError:
243 return 243 return
244 if timestamp: 244
245 for _chat_text in self.content: 245 new_text = ChatText(self, timestamp or None, nick, mymess, msg)
246 if (msg == _chat_text.message and 246
247 timestamp - time.mktime(_chat_text.timestamp) < 5): 247 if timestamp and self.content:
248 #we discard double messages, to avoid backlog / history conflict 248 for idx in range(len(self.content)-1,-1,-1):
249 current_text = self.content[idx]
250 if new_text.timestamp < current_text.timestamp and idx > 0:
251 continue #the new message is older, we need to insert it upper
252
253 #we discard double messages, to avoid backlog / history conflict
254 if idx and self.content[idx-1].message == msg:
249 return 255 return
250 self.content.append(ChatText(self, timestamp or None, nick, mymess, msg)) 256 if idx<len(self.content)-2 and self.content[idx+1].message == msg:
251 if timestamp: 257 return
252 self.content.sort(key=lambda chat_text: chat_text.timestamp) 258
259 self.content.insert(idx+1, new_text)
260 break
261 else:
262 self.content.append(new_text)
263
253 if self.text_list.get_focus()[1] == len(self.content)-2: 264 if self.text_list.get_focus()[1] == len(self.content)-2:
254 #we don't change focus if user is not at the bottom 265 #we don't change focus if user is not at the bottom
255 #as that mean that he is probably watching discussion history 266 #as that mean that he is probably watching discussion history
256 self.text_list.set_focus(len(self.content)-1) 267 self.text_list.set_focus(len(self.content)-1)
257 self.host.redraw() 268 self.host.redraw()