chat patch

This commit is contained in:
unknown 2025-10-04 02:01:29 +03:00
parent 4e50ff865f
commit 1affc2f8d7

View File

@ -1,5 +1,6 @@
from PySide6.QtWidgets import QWidget, QListWidget, QVBoxLayout, QListWidgetItem, QAbstractItemView
from PySide6.QtCore import Qt, QSize, Signal, QLocale
from app.core.localizer import localizer
from typing import List
from app.core.models.chat_models import PrivateChatListItem
from app.ui.widgets.chat_list_item_widget import ChatListItemWidget
@ -194,6 +195,31 @@ class ChatListView(QWidget):
display_ts = ts_dt.strftime('%d.%m.%y')
else:
display_ts = ''
# Override display with app locale rules (via localizer)
try:
qt_locale = QLocale(localizer.lang)
ts_dt_loc = chat.last_message.created_at.astimezone() if (chat.last_message and getattr(chat.last_message, 'created_at', None)) else None
now_loc = datetime.now().astimezone()
if ts_dt_loc:
delta_days2 = (now_loc.date() - ts_dt_loc.date()).days
if delta_days2 == 0:
time_fmt = QLocale.system().timeFormat(QLocale.ShortFormat)
if ('AP' in time_fmt) or ('ap' in time_fmt) or ('a' in time_fmt):
display_ts = ts_dt_loc.strftime('%I:%M %p').lstrip('0')
else:
display_ts = ts_dt_loc.strftime('%H:%M')
elif delta_days2 == 1:
display_ts = 'Вчера' if localizer.lang.startswith('ru') else 'Yesterday'
elif 1 < delta_days2 < 7:
display_ts = qt_locale.dayName(ts_dt_loc.isoweekday(), QLocale.ShortFormat)
elif delta_days2 < 365:
month_name = qt_locale.monthName(ts_dt_loc.month, QLocale.ShortFormat)
display_ts = f"{month_name} {ts_dt_loc.day:02d}"
else:
display_ts = ts_dt_loc.strftime('%d.%m.%y')
except Exception:
pass
# Создаем кастомный виджет
is_outgoing = False
is_read = None
@ -209,6 +235,11 @@ class ChatListView(QWidget):
if chat.last_message and getattr(chat.last_message, 'created_at', None):
ts_utc = chat.last_message.created_at
ts_local = ts_utc.astimezone()
# Localized long format tooltip
try:
qt_locale = QLocale(localizer.lang)
item_widget.set_timestamp_tooltip(qt_locale.toString(ts_local, QLocale.LongFormat))
except Exception:
item_widget.set_timestamp_tooltip(ts_local.strftime('%d.%m.%Y %H:%M:%S'))
else:
item_widget.set_timestamp_tooltip("")