comparison 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
comparison
equal deleted inserted replaced
1748:3a6cd1c14974 1749:d047535e3ed5
22 log = getLogger(__name__) 22 log = getLogger(__name__)
23 from sat_frontends.tools import jid 23 from sat_frontends.tools import jid
24 from sat_frontends.quick_frontend import quick_widgets 24 from sat_frontends.quick_frontend import quick_widgets
25 from sat_frontends.quick_frontend.constants import Const as C 25 from sat_frontends.quick_frontend.constants import Const as C
26 from collections import OrderedDict 26 from collections import OrderedDict
27 from datetime import datetime
28 from time import time
27 29
28 try: 30 try:
29 # FIXME: to be removed when an acceptable solution is here 31 # FIXME: to be removed when an acceptable solution is here
30 unicode('') # XXX: unicode doesn't exist in pyjamas 32 unicode('') # XXX: unicode doesn't exist in pyjamas
31 except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options 33 except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options
141 log.debug(log_msg) 143 log.debug(log_msg)
142 144
143 target = self.target.bare 145 target = self.target.bare
144 146
145 def onHistory(history): 147 def onHistory(history):
148 day_format = "%A, %d %b %Y" # to display the day change
149 previous_day = datetime.now().strftime(day_format)
146 for line in history: 150 for line in history:
147 timestamp, from_jid, to_jid, message, type_, extra = line # FIXME: extra is unused ! 151 timestamp, from_jid, to_jid, message, type_, extra = line # FIXME: extra is unused !
148 if ((self.type == C.CHAT_GROUP and type_ != C.MESS_TYPE_GROUPCHAT) or 152 if ((self.type == C.CHAT_GROUP and type_ != C.MESS_TYPE_GROUPCHAT) or
149 (self.type == C.CHAT_ONE2ONE and type_ == C.MESS_TYPE_GROUPCHAT)): 153 (self.type == C.CHAT_ONE2ONE and type_ == C.MESS_TYPE_GROUPCHAT)):
150 continue 154 continue
155 message_day = datetime.fromtimestamp(float(timestamp or time())).strftime(day_format)
156 if previous_day != message_day:
157 self.printDayChange(message_day)
158 previous_day = message_day
151 extra["timestamp"] = timestamp 159 extra["timestamp"] = timestamp
152 self.newMessage(jid.JID(from_jid), target, message, type_, extra, profile) 160 self.newMessage(jid.JID(from_jid), target, message, type_, extra, profile)
153 self.afterHistoryPrint() 161 self.afterHistoryPrint()
154 162
155 def onHistoryError(err): 163 def onHistoryError(err):
217 - 'me': "/me" information like "/me clenches his fist" ==> "toto clenches his fist" 225 - 'me': "/me" information like "/me clenches his fist" ==> "toto clenches his fist"
218 @param extra (dict): message data 226 @param extra (dict): message data
219 """ 227 """
220 raise NotImplementedError 228 raise NotImplementedError
221 229
230 def printDayChange(self, day):
231 """Display the day on a new line.
232
233 @param day(unicode): day to display (or not if this method is not overwritten)
234 """
235 pass
236
222 def getEntityStates(self, entity): 237 def getEntityStates(self, entity):
223 """Retrieve states for an entity. 238 """Retrieve states for an entity.
224 239
225 @param entity (jid.JID): entity 240 @param entity (jid.JID): entity
226 @return: OrderedDict{unicode: unicode} 241 @return: OrderedDict{unicode: unicode}