chat patch
This commit is contained in:
parent
a2f583e969
commit
a9fb3df4ec
@ -168,6 +168,25 @@ class ChatListView(QWidget):
|
||||
# TODO: Заменить на реальное количество непрочитанных сообщений
|
||||
unread_count = 2
|
||||
|
||||
# Build display timestamp based on recency
|
||||
if chat.last_message and getattr(chat.last_message, 'created_at', None):
|
||||
ts_utc = chat.last_message.created_at
|
||||
ts_dt = ts_utc.astimezone()
|
||||
now = datetime.now().astimezone()
|
||||
delta_days = (now.date() - ts_dt.date()).days
|
||||
if delta_days == 0:
|
||||
display_ts = ts_dt.strftime('%H:%M')
|
||||
elif delta_days == 1:
|
||||
display_ts = 'Вчера'
|
||||
elif 1 < delta_days < 7:
|
||||
weekdays = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс']
|
||||
display_ts = weekdays[ts_dt.weekday()]
|
||||
elif delta_days < 365:
|
||||
display_ts = ts_dt.strftime('%b %d')
|
||||
else:
|
||||
display_ts = ts_dt.strftime('%d.%m.%y')
|
||||
else:
|
||||
display_ts = ''
|
||||
# Создаем кастомный виджет
|
||||
is_outgoing = False
|
||||
is_read = None
|
||||
@ -177,11 +196,13 @@ class ChatListView(QWidget):
|
||||
if is_outgoing: unread_count = 0
|
||||
is_read = bool(chat.last_message.is_viewed)
|
||||
|
||||
item_widget = ChatListItemWidget(companion_name, last_msg, timestamp, unread_count=unread_count, is_outgoing=is_outgoing, is_read=is_read)
|
||||
item_widget = ChatListItemWidget(companion_name, last_msg, display_ts, unread_count=unread_count, is_outgoing=is_outgoing, is_read=is_read)
|
||||
# Tooltip with full date/time on hover
|
||||
try:
|
||||
if chat.last_message and getattr(chat.last_message, 'created_at', None):
|
||||
item_widget.set_timestamp_tooltip(chat.last_message.created_at.strftime('%d.%m.%Y %H:%M:%S'))
|
||||
ts_utc = chat.last_message.created_at
|
||||
ts_local = ts_utc.astimezone()
|
||||
item_widget.set_timestamp_tooltip(ts_local.strftime('%d.%m.%Y %H:%M:%S'))
|
||||
else:
|
||||
item_widget.set_timestamp_tooltip("")
|
||||
except Exception:
|
||||
@ -197,3 +218,5 @@ class ChatListView(QWidget):
|
||||
self.chat_items_map[id(list_item)] = chat.chat_id
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user