chat patch
This commit is contained in:
		
							parent
							
								
									51dde0999d
								
							
						
					
					
						commit
						e0e6abd453
					
				@ -10,8 +10,9 @@ from uuid import UUID
 | 
			
		||||
class ChatListView(QWidget):
 | 
			
		||||
    chat_selected = Signal(UUID)
 | 
			
		||||
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
    def __init__(self, current_user_id: UUID = None):
 | 
			
		||||
        super().__init__()
 | 
			
		||||
        self.current_user_id = current_user_id
 | 
			
		||||
        self.chat_items_map = {}
 | 
			
		||||
        self.init_ui()
 | 
			
		||||
        self.update_theme()
 | 
			
		||||
@ -146,9 +147,9 @@ class ChatListView(QWidget):
 | 
			
		||||
            if chat.chat_type == "self":
 | 
			
		||||
                companion_name = "Избранное"
 | 
			
		||||
            elif chat.chat_data and 'login' in chat.chat_data:
 | 
			
		||||
                print("=============================")
 | 
			
		||||
                print("chat.chat_data", chat.chat_data)
 | 
			
		||||
                print("=============================")
 | 
			
		||||
                # print("=============================")
 | 
			
		||||
                # print("chat.chat_data", chat.chat_data)
 | 
			
		||||
                # print("=============================")
 | 
			
		||||
                if chat.chat_data['custom_name']:
 | 
			
		||||
                    companion_name = "@"+chat.chat_data['login'] + " (" + chat.chat_data['custom_name'] + ")"
 | 
			
		||||
                else:
 | 
			
		||||
@ -168,7 +169,15 @@ class ChatListView(QWidget):
 | 
			
		||||
            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)
 | 
			
		||||
@ -179,3 +188,4 @@ class ChatListView(QWidget):
 | 
			
		||||
            # Сохраняем ID чата в словаре
 | 
			
		||||
            self.chat_items_map[id(list_item)] = chat.chat_id
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -371,7 +371,7 @@ class YobbleHomeView(QWidget):
 | 
			
		||||
        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.content_stack.addWidget(self.chat_list_view)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -3,12 +3,16 @@ from PySide6.QtGui import QPixmap, QPainter, QColor, QBrush
 | 
			
		||||
from PySide6.QtCore import Qt
 | 
			
		||||
from app.core.theme import theme_manager
 | 
			
		||||
 | 
			
		||||
from typing import Optional
 | 
			
		||||
 | 
			
		||||
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__()
 | 
			
		||||
        # Ensure fully transparent background for the item widget
 | 
			
		||||
        self.setAutoFillBackground(False)
 | 
			
		||||
        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.update_theme()
 | 
			
		||||
        # Ensure badge shape reflects current count
 | 
			
		||||
@ -43,13 +47,24 @@ class ChatListItemWidget(QWidget):
 | 
			
		||||
        meta_layout.setAlignment(Qt.AlignRight)
 | 
			
		||||
        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.unread_label = QLabel(str(unread_count) if unread_count > 0 else "")
 | 
			
		||||
        self.unread_label.setAlignment(Qt.AlignCenter)
 | 
			
		||||
        self.unread_label.setMargin(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.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.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;")
 | 
			
		||||
        # 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_text = "#ffffff"
 | 
			
		||||
@ -102,6 +124,17 @@ class ChatListItemWidget(QWidget):
 | 
			
		||||
            self.unread_label.setStyleSheet(
 | 
			
		||||
                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):
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user