Compare commits

...

2 Commits

Author SHA1 Message Date
unknown
4e50ff865f chat patch 2025-10-04 01:51:46 +03:00
unknown
a9fb3df4ec chat patch 2025-10-04 01:42:21 +03:00

View File

@ -1,5 +1,5 @@
from PySide6.QtWidgets import QWidget, QListWidget, QVBoxLayout, QListWidgetItem, QAbstractItemView 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 typing import List
from app.core.models.chat_models import PrivateChatListItem from app.core.models.chat_models import PrivateChatListItem
from app.ui.widgets.chat_list_item_widget import ChatListItemWidget from app.ui.widgets.chat_list_item_widget import ChatListItemWidget
@ -168,6 +168,32 @@ class ChatListView(QWidget):
# TODO: Заменить на реальное количество непрочитанных сообщений # TODO: Заменить на реальное количество непрочитанных сообщений
unread_count = 2 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_outgoing = False
is_read = None is_read = None
@ -177,11 +203,13 @@ class ChatListView(QWidget):
if is_outgoing: unread_count = 0 if is_outgoing: unread_count = 0
is_read = bool(chat.last_message.is_viewed) 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 # Tooltip with full date/time on hover
try: try:
if chat.last_message and getattr(chat.last_message, 'created_at', None): 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: else:
item_widget.set_timestamp_tooltip("") item_widget.set_timestamp_tooltip("")
except Exception: except Exception:
@ -197,3 +225,5 @@ class ChatListView(QWidget):
self.chat_items_map[id(list_item)] = chat.chat_id self.chat_items_map[id(list_item)] = chat.chat_id