chat patch

This commit is contained in:
unknown 2025-10-04 01:21:23 +03:00
parent 51dde0999d
commit e0e6abd453
3 changed files with 51 additions and 8 deletions

View File

@ -10,8 +10,9 @@ from uuid import UUID
class ChatListView(QWidget): class ChatListView(QWidget):
chat_selected = Signal(UUID) chat_selected = Signal(UUID)
def __init__(self): def __init__(self, current_user_id: UUID = None):
super().__init__() super().__init__()
self.current_user_id = current_user_id
self.chat_items_map = {} self.chat_items_map = {}
self.init_ui() self.init_ui()
self.update_theme() self.update_theme()
@ -146,9 +147,9 @@ class ChatListView(QWidget):
if chat.chat_type == "self": if chat.chat_type == "self":
companion_name = "Избранное" companion_name = "Избранное"
elif chat.chat_data and 'login' in chat.chat_data: elif chat.chat_data and 'login' in chat.chat_data:
print("=============================") # print("=============================")
print("chat.chat_data", chat.chat_data) # print("chat.chat_data", chat.chat_data)
print("=============================") # print("=============================")
if chat.chat_data['custom_name']: if chat.chat_data['custom_name']:
companion_name = "@"+chat.chat_data['login'] + " (" + chat.chat_data['custom_name'] + ")" companion_name = "@"+chat.chat_data['login'] + " (" + chat.chat_data['custom_name'] + ")"
else: else:
@ -168,7 +169,15 @@ class ChatListView(QWidget):
unread_count = 2 unread_count = 2
# Создаем кастомный виджет # Создаем кастомный виджет
item_widget = ChatListItemWidget(companion_name, last_msg, timestamp, unread_count=unread_count) is_outgoing = False
is_read = None
if chat.last_message:
if self.current_user_id is not None:
is_outgoing = (str(chat.last_message.sender_id) == str(self.current_user_id))
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)
# Создаем элемент списка и устанавливаем для него наш виджет # Создаем элемент списка и устанавливаем для него наш виджет
list_item = QListWidgetItem(self.chat_list) list_item = QListWidgetItem(self.chat_list)
@ -179,3 +188,4 @@ class ChatListView(QWidget):
# Сохраняем ID чата в словаре # Сохраняем ID чата в словаре
self.chat_items_map[id(list_item)] = chat.chat_id self.chat_items_map[id(list_item)] = chat.chat_id

View File

@ -371,7 +371,7 @@ class YobbleHomeView(QWidget):
self.content_stack.addWidget(self.music_label) self.content_stack.addWidget(self.music_label)
# Чаты # Чаты
self.chat_list_view = ChatListView() self.chat_list_view = ChatListView(current_user_id=self.current_user_id)
self.chat_list_view.chat_selected.connect(self.open_chat_view) self.chat_list_view.chat_selected.connect(self.open_chat_view)
self.content_stack.addWidget(self.chat_list_view) self.content_stack.addWidget(self.chat_list_view)

View File

@ -3,12 +3,16 @@ from PySide6.QtGui import QPixmap, QPainter, QColor, QBrush
from PySide6.QtCore import Qt from PySide6.QtCore import Qt
from app.core.theme import theme_manager from app.core.theme import theme_manager
from typing import Optional
class ChatListItemWidget(QWidget): class ChatListItemWidget(QWidget):
def __init__(self, companion_name, last_message, timestamp, avatar_path=None, unread_count=0): def __init__(self, companion_name, last_message, timestamp, avatar_path=None, unread_count=0, is_outgoing: bool = False, is_read: Optional[bool] = None):
super().__init__() super().__init__()
# Ensure fully transparent background for the item widget # Ensure fully transparent background for the item widget
self.setAutoFillBackground(False) self.setAutoFillBackground(False)
self.setStyleSheet("background-color: transparent;") self.setStyleSheet("background-color: transparent;")
self.is_outgoing = is_outgoing
self.is_read = is_read
self.init_ui(companion_name, last_message, timestamp, avatar_path, unread_count) self.init_ui(companion_name, last_message, timestamp, avatar_path, unread_count)
self.update_theme() self.update_theme()
# Ensure badge shape reflects current count # Ensure badge shape reflects current count
@ -43,13 +47,24 @@ class ChatListItemWidget(QWidget):
meta_layout.setAlignment(Qt.AlignRight) meta_layout.setAlignment(Qt.AlignRight)
meta_layout.setContentsMargins(0, 0, 0, 0) meta_layout.setContentsMargins(0, 0, 0, 0)
# Delivery/read status icon (left of timestamp)
self.status_label = QLabel("")
self.status_label.setFixedWidth(16)
self.status_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
self.timestamp_label = QLabel(timestamp) self.timestamp_label = QLabel(timestamp)
self.unread_label = QLabel(str(unread_count) if unread_count > 0 else "") self.unread_label = QLabel(str(unread_count) if unread_count > 0 else "")
self.unread_label.setAlignment(Qt.AlignCenter) self.unread_label.setAlignment(Qt.AlignCenter)
self.unread_label.setMargin(0) self.unread_label.setMargin(0)
self.unread_label.setContentsMargins(0, 0, 0, 0) self.unread_label.setContentsMargins(0, 0, 0, 0)
meta_layout.addWidget(self.timestamp_label) # Put status and time on a single row aligned right
time_row = QHBoxLayout()
time_row.setSpacing(4)
time_row.setContentsMargins(0, 0, 0, 0)
time_row.addWidget(self.status_label)
time_row.addWidget(self.timestamp_label)
time_row.addStretch()
meta_layout.addLayout(time_row)
meta_layout.addWidget(self.unread_label) meta_layout.addWidget(self.unread_label)
meta_layout.addStretch() meta_layout.addStretch()
@ -67,6 +82,13 @@ class ChatListItemWidget(QWidget):
self.name_label.setStyleSheet(f"font-weight: bold; font-size: 11pt; color: {palette['text']}; background-color: transparent;") self.name_label.setStyleSheet(f"font-weight: bold; font-size: 11pt; color: {palette['text']}; background-color: transparent;")
self.last_message_label.setStyleSheet(f"font-size: 9pt; color: {palette['text_secondary']}; background-color: transparent;") self.last_message_label.setStyleSheet(f"font-size: 9pt; color: {palette['text_secondary']}; background-color: transparent;")
self.timestamp_label.setStyleSheet(f"font-size: 8pt; color: {palette['text_secondary']}; background-color: transparent;") self.timestamp_label.setStyleSheet(f"font-size: 8pt; color: {palette['text_secondary']}; background-color: transparent;")
# Status color depends on state; default to secondary
status_color = palette['text_secondary']
if getattr(self, 'is_outgoing', False):
if getattr(self, 'is_read', None) is True:
status_color = palette['accent']
self.status_label.setStyleSheet(f"font-size: 9pt; color: {status_color}; background-color: transparent;")
self._update_status_icon()
unread_bg = palette['accent'] unread_bg = palette['accent']
unread_text = "#ffffff" unread_text = "#ffffff"
@ -103,6 +125,17 @@ class ChatListItemWidget(QWidget):
self._unread_base_style + f" border-radius: {height//2}px; padding: 0 6px;" self._unread_base_style + f" border-radius: {height//2}px; padding: 0 6px;"
) )
def _update_status_icon(self):
# Show ticks only for outgoing messages with a known read state
if getattr(self, 'is_outgoing', False) and getattr(self, 'is_read', None) is not None:
if self.is_read:
self.status_label.setText("✓✓")
else:
self.status_label.setText("")
self.status_label.setVisible(True)
else:
self.status_label.setVisible(False)
def set_avatar(self, image_path): def set_avatar(self, image_path):
"""Устанавливает аватар. Если путь не указан, создает заглушку.""" """Устанавливает аватар. Если путь не указан, создает заглушку."""