comparison frontends/src/quick_frontend/quick_chat.py @ 2029:62a99c214b57

primitivus, quick frontend (chat): moved time text generation to QuickChat
author Goffi <goffi@goffi.org>
date Mon, 08 Aug 2016 21:05:04 +0200
parents cdb2591d0b8b
children e3f1bd9dd009
comparison
equal deleted inserted replaced
2028:70bd7b242a9e 2029:62a99c214b57
23 from sat.core import exceptions 23 from sat.core import exceptions
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 sat_frontends.tools import jid 27 from sat_frontends.tools import jid
28 import locale
29 import time
28 30
29 ROOM_USER_JOINED = 'ROOM_USER_JOINED' 31 ROOM_USER_JOINED = 'ROOM_USER_JOINED'
30 ROOM_USER_LEFT = 'ROOM_USER_LEFT' 32 ROOM_USER_LEFT = 'ROOM_USER_LEFT'
31 ROOM_USER_MOVED = (ROOM_USER_JOINED, ROOM_USER_LEFT) 33 ROOM_USER_MOVED = (ROOM_USER_JOINED, ROOM_USER_LEFT)
32 34
97 return mess 99 return mess
98 except StopIteration: 100 except StopIteration:
99 log.error(u"Can't find message for uid {}".format(self.uid)) 101 log.error(u"Can't find message for uid {}".format(self.uid))
100 return '' 102 return ''
101 103
104 @property
105 def time_text(self):
106 """Return timestamp in a nicely formatted way"""
107 # if the message was sent before today, we print the full date
108 timestamp = time.localtime(self.timestamp)
109 time_format = u"%c" if timestamp < self.parent.day_change else u"%H:%M"
110 return time.strftime(time_format, timestamp).decode(locale.getlocale()[1])
111
102 def getNick(self, entity): 112 def getNick(self, entity):
103 """Return nick of an entity when possible""" 113 """Return nick of an entity when possible"""
104 contact_list = self.host.contact_lists[self.profile] 114 contact_list = self.host.contact_lists[self.profile]
105 if self.type == C.MESS_TYPE_INFO and self.info_type in ROOM_USER_MOVED: 115 if self.type == C.MESS_TYPE_INFO and self.info_type in ROOM_USER_MOVED:
106 try: 116 try:
189 if occupants is not None: 199 if occupants is not None:
190 raise exceptions.InternalError(u"only group chat can have occupants") 200 raise exceptions.InternalError(u"only group chat can have occupants")
191 self.messages = OrderedDict() # key: uid, value: Message instance 201 self.messages = OrderedDict() # key: uid, value: Message instance
192 self.games = {} # key=game name (unicode), value=instance of quick_games.RoomGame 202 self.games = {} # key=game name (unicode), value=instance of quick_games.RoomGame
193 self.subject = subject 203 self.subject = subject
204 self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00 %Y")) # struct_time of day changing time
194 205
195 def postInit(self): 206 def postInit(self):
196 """Method to be called by frontend after widget is initialised 207 """Method to be called by frontend after widget is initialised
197 208
198 handle the display of history and subject 209 handle the display of history and subject