primitivus, quick frontend (chat): moved time text generation to QuickChat
This commit is contained in:
parent
ae50946479
commit
56211b33c6
2 changed files with 12 additions and 7 deletions
|
|
@ -30,8 +30,6 @@ from sat_frontends.primitivus.constants import Const as C
|
|||
from sat_frontends.primitivus.keys import action_key_map as a_key
|
||||
from sat_frontends.primitivus.widget import PrimitivusWidget
|
||||
from sat_frontends.primitivus.contact_list import ContactList
|
||||
import time
|
||||
import locale
|
||||
from functools import total_ordering
|
||||
import bisect
|
||||
|
||||
|
|
@ -47,7 +45,6 @@ class MessageWidget(urwid.WidgetWrap):
|
|||
"""
|
||||
self.mess_data = mess_data
|
||||
mess_data.widgets.add(self)
|
||||
self.timestamp = time.localtime(mess_data.timestamp)
|
||||
super(MessageWidget, self).__init__(urwid.Text(self.markup))
|
||||
|
||||
@property
|
||||
|
|
@ -119,10 +116,8 @@ class MessageWidget(urwid.WidgetWrap):
|
|||
|
||||
# timestamp
|
||||
if self.parent.show_timestamp:
|
||||
# if the message was sent before today, we print the full date
|
||||
time_format = u"%c" if self.timestamp < self.parent.day_change else u"%H:%M"
|
||||
attr = 'msg_mention' if mention else 'date'
|
||||
markup.append((attr, u"[{}]".format(time.strftime(time_format, self.timestamp).decode(locale.getlocale()[1]))))
|
||||
markup.append((attr, u"[{}]".format(d.time_text)))
|
||||
else:
|
||||
if mention:
|
||||
markup.append(('msg_mention', '[*]'))
|
||||
|
|
@ -284,7 +279,6 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
|
|||
# focus marker is a separator indicated last visible message before focus was lost
|
||||
self.focus_marker = None # link to current marker
|
||||
self.focus_marker_set = None # True if a new marker has been inserted
|
||||
self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00 %Y")) # struct_time of day changing time
|
||||
self.show_timestamp = True
|
||||
self.show_short_nick = False
|
||||
self.show_title = 1 # 0: clip title; 1: full title; 2: no title
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ from sat_frontends.quick_frontend import quick_widgets
|
|||
from sat_frontends.quick_frontend.constants import Const as C
|
||||
from collections import OrderedDict
|
||||
from sat_frontends.tools import jid
|
||||
import locale
|
||||
import time
|
||||
|
||||
ROOM_USER_JOINED = 'ROOM_USER_JOINED'
|
||||
ROOM_USER_LEFT = 'ROOM_USER_LEFT'
|
||||
|
|
@ -99,6 +101,14 @@ class Message(object):
|
|||
log.error(u"Can't find message for uid {}".format(self.uid))
|
||||
return ''
|
||||
|
||||
@property
|
||||
def time_text(self):
|
||||
"""Return timestamp in a nicely formatted way"""
|
||||
# if the message was sent before today, we print the full date
|
||||
timestamp = time.localtime(self.timestamp)
|
||||
time_format = u"%c" if timestamp < self.parent.day_change else u"%H:%M"
|
||||
return time.strftime(time_format, timestamp).decode(locale.getlocale()[1])
|
||||
|
||||
def getNick(self, entity):
|
||||
"""Return nick of an entity when possible"""
|
||||
contact_list = self.host.contact_lists[self.profile]
|
||||
|
|
@ -191,6 +201,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
self.messages = OrderedDict() # key: uid, value: Message instance
|
||||
self.games = {} # key=game name (unicode), value=instance of quick_games.RoomGame
|
||||
self.subject = subject
|
||||
self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00 %Y")) # struct_time of day changing time
|
||||
|
||||
def postInit(self):
|
||||
"""Method to be called by frontend after widget is initialised
|
||||
|
|
|
|||
Loading…
Reference in a new issue