From 99785755e1a271a2c135966a15d011c360898e31 Mon Sep 17 00:00:00 2001 From: souliane Date: Tue, 15 Dec 2015 20:05:27 +0100 Subject: [PATCH] quick_frontend: restore printing the day change while displaying history --- frontends/src/quick_frontend/quick_chat.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/frontends/src/quick_frontend/quick_chat.py b/frontends/src/quick_frontend/quick_chat.py index 7ade0264..00df6e4a 100644 --- a/frontends/src/quick_frontend/quick_chat.py +++ b/frontends/src/quick_frontend/quick_chat.py @@ -24,6 +24,8 @@ from sat_frontends.tools import jid 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 @@ class QuickChat(quick_widgets.QuickWidget): 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 @@ class QuickChat(quick_widgets.QuickWidget): """ 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.