Mercurial > libervia-backend
comparison frontends/src/primitivus/chat.py @ 1223:802b7e6bf098
frontends: printInfo and printMessage timestamp attribute defaults to None instead of ''
author | souliane <souliane@mailoo.org> |
---|---|
date | Sat, 04 Oct 2014 10:23:13 +0200 |
parents | 6184779544c7 |
children | e3a9ea76de35 |
comparison
equal
deleted
inserted
replaced
1222:e6e0ea4dc835 | 1223:802b7e6bf098 |
---|---|
288 """Refresh or scroll down the focus after the history is printed""" | 288 """Refresh or scroll down the focus after the history is printed""" |
289 if len(self.content): | 289 if len(self.content): |
290 self.text_list.focus_position = len(self.content) - 1 # scroll down | 290 self.text_list.focus_position = len(self.content) - 1 # scroll down |
291 self.host.redraw() | 291 self.host.redraw() |
292 | 292 |
293 def printMessage(self, from_jid, msg, profile, timestamp=""): | 293 def printMessage(self, from_jid, msg, profile, timestamp=None): |
294 assert isinstance(from_jid, JID) | 294 assert isinstance(from_jid, JID) |
295 try: | 295 try: |
296 jid, nick, mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp) | 296 jid, nick, mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp) |
297 except TypeError: | 297 except TypeError: |
298 return | 298 return |
299 | 299 |
300 new_text = ChatText(self, timestamp or None, nick, mymess, msg) | 300 new_text = ChatText(self, timestamp, nick, mymess, msg) |
301 | 301 |
302 if timestamp and self.content: | 302 if timestamp and self.content: |
303 for idx in range(len(self.content) - 1, -1, -1): | 303 for idx in range(len(self.content) - 1, -1, -1): |
304 current_text = self.content[idx] | 304 current_text = self.content[idx] |
305 older = new_text.timestamp < current_text.timestamp | 305 older = new_text.timestamp < current_text.timestamp |
306 if older and idx > 0: | 306 if older and idx > 0: |
307 continue # the new message is older, we need to insert it upper | 307 continue # the new message is older, we need to insert it upper |
308 | 308 |
309 #we discard double messages, to avoid backlog / history conflict | 309 #we discard double messages, to avoid backlog / history conflict |
310 # FIXME: messages that have been sent several times will be displayed only once | |
310 if ((idx and self.content[idx - 1].message == msg) or | 311 if ((idx and self.content[idx - 1].message == msg) or |
311 (self.content[idx].message == msg) or | 312 (self.content[idx].message == msg) or |
312 (idx < len(self.content) - 2 and self.content[idx + 1].message)): | 313 (idx < len(self.content) - 2 and self.content[idx + 1].message)): |
313 return | 314 return |
314 | 315 |
320 # XXX: do not send notifications for each line of the history being displayed | 321 # XXX: do not send notifications for each line of the history being displayed |
321 # FIXME: this must be changed in the future if the timestamp is passed with | 322 # FIXME: this must be changed in the future if the timestamp is passed with |
322 # all messages and not only with the messages coming from the history. | 323 # all messages and not only with the messages coming from the history. |
323 self._notify(from_jid, msg) | 324 self._notify(from_jid, msg) |
324 | 325 |
325 def printInfo(self, msg, type_='normal', timestamp=""): | 326 def printInfo(self, msg, type_='normal', timestamp=None): |
326 """Print general info | 327 """Print general info |
327 @param msg: message to print | 328 @param msg: message to print |
328 @type_: one of: | 329 @type_: one of: |
329 normal: general info like "toto has joined the room" | 330 normal: general info like "toto has joined the room" |
330 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" | 331 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" |
331 """ | 332 @param timestamp (float): number of seconds since epoch |
332 _widget = ChatText(self, timestamp or None, None, False, msg, is_info=True) | 333 """ |
334 _widget = ChatText(self, timestamp, None, False, msg, is_info=True) | |
333 self.content.append(_widget) | 335 self.content.append(_widget) |
334 self._notify(msg=msg) | 336 self._notify(msg=msg) |
335 | 337 |
336 def _notify(self, from_jid="somebody", msg=""): | 338 def _notify(self, from_jid="somebody", msg=""): |
337 """Notify the user of a new message if primitivus doesn't have the focus. | 339 """Notify the user of a new message if primitivus doesn't have the focus. |