From 1affc2f8d755b4898f0f64a4466f25ad6b078fc8 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 4 Oct 2025 02:01:29 +0300 Subject: [PATCH] chat patch --- app/ui/views/chat_list_view.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/app/ui/views/chat_list_view.py b/app/ui/views/chat_list_view.py index e5a357b..fe1ab4d 100644 --- a/app/ui/views/chat_list_view.py +++ b/app/ui/views/chat_list_view.py @@ -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,7 +235,12 @@ 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() - item_widget.set_timestamp_tooltip(ts_local.strftime('%d.%m.%Y %H:%M:%S')) + # 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("") except Exception: