Compare commits
2 Commits
a2f583e969
...
4e50ff865f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e50ff865f | ||
|
|
a9fb3df4ec |
@ -1,5 +1,5 @@
|
||||
from PySide6.QtWidgets import QWidget, QListWidget, QVBoxLayout, QListWidgetItem, QAbstractItemView
|
||||
from PySide6.QtCore import Qt, QSize, Signal
|
||||
from PySide6.QtCore import Qt, QSize, Signal, QLocale
|
||||
from typing import List
|
||||
from app.core.models.chat_models import PrivateChatListItem
|
||||
from app.ui.widgets.chat_list_item_widget import ChatListItemWidget
|
||||
@ -168,6 +168,32 @@ 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:
|
||||
# Respect system 12/24h preference
|
||||
time_fmt = QLocale.system().timeFormat(QLocale.ShortFormat)
|
||||
if ('AP' in time_fmt) or ('ap' in time_fmt) or ('a' in time_fmt):
|
||||
# 12-hour clock
|
||||
display_ts = ts_dt.strftime('%I:%M %p').lstrip('0')
|
||||
else:
|
||||
# 24-hour clock
|
||||
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 +203,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 +225,5 @@ class ChatListView(QWidget):
|
||||
self.chat_items_map[id(list_item)] = chat.chat_id
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user