diff frontends/src/quick_frontend/quick_chat.py @ 1749:d047535e3ed5

quick_frontend: restore printing the day change while displaying history
author souliane <souliane@mailoo.org>
date Tue, 15 Dec 2015 20:05:27 +0100
parents 3a6cd1c14974
children 2e2fb462729a
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_chat.py	Sat Dec 12 12:18:54 2015 +0100
+++ b/frontends/src/quick_frontend/quick_chat.py	Tue Dec 15 20:05:27 2015 +0100
@@ -24,6 +24,8 @@
 from sat_frontends.quick_frontend import quick_widgets
 from sat_frontends.quick_frontend.constants import Const as C
 from collections import OrderedDict
+from datetime import datetime
+from time import time
 
 try:
     # FIXME: to be removed when an acceptable solution is here
@@ -143,11 +145,17 @@
         target = self.target.bare
 
         def onHistory(history):
+            day_format = "%A, %d %b %Y"  # to display the day change
+            previous_day = datetime.now().strftime(day_format)
             for line in history:
                 timestamp, from_jid, to_jid, message, type_, extra = line  # FIXME: extra is unused !
                 if ((self.type == C.CHAT_GROUP and type_ != C.MESS_TYPE_GROUPCHAT) or
                    (self.type == C.CHAT_ONE2ONE and type_ == C.MESS_TYPE_GROUPCHAT)):
                     continue
+                message_day = datetime.fromtimestamp(float(timestamp or time())).strftime(day_format)
+                if previous_day != message_day:
+                    self.printDayChange(message_day)
+                    previous_day = message_day
                 extra["timestamp"] = timestamp
                 self.newMessage(jid.JID(from_jid), target, message, type_, extra, profile)
             self.afterHistoryPrint()
@@ -219,6 +227,13 @@
         """
         raise NotImplementedError
 
+    def printDayChange(self, day):
+        """Display the day on a new line.
+
+        @param day(unicode): day to display (or not if this method is not overwritten)
+        """
+        pass
+
     def getEntityStates(self, entity):
         """Retrieve states for an entity.