quick_frontend: restore printing the day change while displaying history

This commit is contained in:
souliane 2015-12-15 20:05:27 +01:00
commit 99785755e1

View file

@ -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.