联系人列表修复

main
杨博文 2 months ago
parent 83b215327d
commit 49701069c8

1
.gitignore vendored

@ -3,3 +3,4 @@ __pycache__/
.kiro/*
client_gui.log

@ -58,3 +58,56 @@
2025-12-26 22:56:09,112 - __main__ - INFO - Connected to server
2025-12-26 22:56:09,132 - client.app - INFO - Online users updated: 1 users
2025-12-26 22:56:09,133 - __main__ - INFO - Online users: 1
2025-12-26 22:56:09,633 - client.app - INFO - Online users updated: 1 users
2025-12-26 22:56:09,634 - __main__ - INFO - Online users: 1
2025-12-26 22:58:17,789 - client.ui.main_window - INFO - MainWindow cleanup
2025-12-26 22:58:17,802 - __main__ - INFO - Cleaning up resources...
2025-12-26 22:58:17,803 - __main__ - ERROR - Worker error: Event loop stopped before Future completed.
2025-12-26 22:58:17,806 - __main__ - ERROR - Error stopping client: Event loop is closed
2025-12-26 22:58:17,806 - __main__ - INFO - Cleanup completed
2025-12-26 22:58:17,893 - asyncio - ERROR - Task was destroyed but it is pending!
task: <Task pending name='Task-1314' coro=<BaseProactorEventLoop.sock_recvfrom() done, defined at E:\Miniconda3\Lib\asyncio\proactor_events.py:710> wait_for=<_OverlappedFuture cancelled> cb=[_release_waiter(<Future pendi...ask_wakeup()]>)() at E:\Miniconda3\Lib\asyncio\tasks.py:431]>
2025-12-26 22:58:17,894 - asyncio - ERROR - Task was destroyed but it is pending!
task: <Task cancelling name='Task-3' coro=<ConnectionManager._heartbeat_loop() running at D:\onedrive\桌面\chatProgram\chatProgram\client\connection_manager.py:383> wait_for=<Future cancelled>>
2025-12-26 22:58:17,894 - asyncio - ERROR - Task was destroyed but it is pending!
task: <Task pending name='Task-4' coro=<ConnectionManager._receive_loop() running at D:\onedrive\桌面\chatProgram\chatProgram\client\connection_manager.py:415> wait_for=<Future pending cb=[Task.task_wakeup()]>>
2025-12-26 22:58:17,895 - asyncio - ERROR - Task was destroyed but it is pending!
task: <Task pending name='Task-5' coro=<ConnectionManager._lan_listen_loop() running at D:\onedrive\桌面\chatProgram\chatProgram\client\connection_manager.py:672> wait_for=<Future pending cb=[Task.task_wakeup()]>>
2025-12-26 23:03:26,489 - client.ui.login_dialog - INFO - LoginDialog initialized
2025-12-26 23:03:33,742 - client.ui.login_dialog - INFO - User logged in: ybw
2025-12-26 23:03:34,455 - client.ui.main_window - INFO - MainWindow initialized
2025-12-26 23:03:34,456 - client.ui.main_window - INFO - Current user set: ybw
2025-12-26 23:03:34,469 - client.ui.system_tray - INFO - SystemTrayManager initialized
2025-12-26 23:03:34,526 - client.connection_manager - INFO - ConnectionManager initialized
2025-12-26 23:03:34,529 - client.file_transfer - INFO - FileTransferModule initialized
2025-12-26 23:03:34,529 - client.image_processor - INFO - ImageProcessor initialized
2025-12-26 23:03:34,530 - client.media_player - INFO - AudioPlayer initialized
2025-12-26 23:03:34,530 - client.media_player - INFO - VideoPlayer initialized
2025-12-26 23:03:34,530 - client.media_player - INFO - MediaPlayer initialized
2025-12-26 23:03:34,530 - client.app - INFO - P2PClientApp initialized
2025-12-26 23:03:34,537 - client.connection_manager - INFO - Connection state changed: disconnected -> connecting (Connecting to server)
2025-12-26 23:03:34,537 - client.app - INFO - Connection state changed: connecting (Connecting to server)
2025-12-26 23:03:34,579 - client.connection_manager - INFO - Connection state changed: connecting -> connected (Connected to server)
2025-12-26 23:03:34,579 - client.app - INFO - Connection state changed: connected (Connected to server)
2025-12-26 23:03:34,580 - client.connection_manager - INFO - LAN listener started on port 8889
2025-12-26 23:03:34,580 - client.connection_manager - INFO - Connected to server 113.45.148.222:8888
2025-12-26 23:03:34,580 - client.app - INFO - Client started for user: ybw
2025-12-26 23:03:34,580 - client.voice_chat - INFO - VoiceChatModule initialized
2025-12-26 23:03:34,582 - __main__ - INFO - Connected to server
2025-12-26 23:03:34,602 - client.app - INFO - Online users updated: 2 users
2025-12-26 23:03:34,602 - __main__ - INFO - Online users: 2
2025-12-26 23:03:35,103 - client.app - INFO - Online users updated: 2 users
2025-12-26 23:03:35,104 - __main__ - INFO - Online users: 2
2025-12-26 23:07:22,202 - client.ui.main_window - INFO - MainWindow cleanup
2025-12-26 23:07:22,214 - __main__ - INFO - Cleaning up resources...
2025-12-26 23:07:22,214 - __main__ - ERROR - Worker error: Event loop stopped before Future completed.
2025-12-26 23:07:22,219 - __main__ - ERROR - Error stopping client: Event loop is closed
2025-12-26 23:07:22,219 - __main__ - INFO - Cleanup completed
2025-12-26 23:07:22,329 - asyncio - ERROR - Task was destroyed but it is pending!
task: <Task pending name='Task-2321' coro=<BaseProactorEventLoop.sock_recvfrom() done, defined at E:\Miniconda3\Lib\asyncio\proactor_events.py:710> wait_for=<_OverlappedFuture cancelled> cb=[_release_waiter(<Future pendi...ask_wakeup()]>)() at E:\Miniconda3\Lib\asyncio\tasks.py:431]>
2025-12-26 23:07:22,331 - asyncio - ERROR - Task was destroyed but it is pending!
task: <Task cancelling name='Task-3' coro=<ConnectionManager._heartbeat_loop() running at D:\onedrive\桌面\chatProgram\chatProgram\client\connection_manager.py:383> wait_for=<Future cancelled>>
2025-12-26 23:07:22,332 - asyncio - ERROR - Task was destroyed but it is pending!
task: <Task pending name='Task-4' coro=<ConnectionManager._receive_loop() running at D:\onedrive\桌面\chatProgram\chatProgram\client\connection_manager.py:415> wait_for=<Future pending cb=[Task.task_wakeup()]>>
2025-12-26 23:07:22,334 - asyncio - ERROR - Task was destroyed but it is pending!
task: <Task pending name='Task-5' coro=<ConnectionManager._lan_listen_loop() running at D:\onedrive\桌面\chatProgram\chatProgram\client\connection_manager.py:672> wait_for=<Future pending cb=[Task.task_wakeup()]>>

@ -222,6 +222,15 @@ class P2PChatGUI(QObject):
if self._current_user:
self.main_window.set_current_user(self._current_user)
# 创建并设置联系人列表组件
self._contact_list_widget = ContactListWidget()
self.main_window.set_contact_list_widget(self._contact_list_widget)
# 连接联系人列表信号
self._contact_list_widget.contact_selected.connect(self._on_contact_selected)
self._contact_list_widget.contact_double_clicked.connect(self._on_contact_double_clicked)
self._contact_list_widget.refresh_requested.connect(self._refresh_users)
# 设置系统托盘
try:
tray = SystemTrayManager(self.main_window)
@ -331,6 +340,16 @@ class P2PChatGUI(QObject):
self.main_window._statusbar.showMessage(
f"在线用户: {len(users)}", 3000
)
# 更新联系人列表(排除自己)
if hasattr(self, '_contact_list_widget') and self._contact_list_widget:
# 过滤掉当前用户自己
other_users = [
user for user in users
if self._current_user is None or user.user_id != self._current_user.user_id
]
self._contact_list_widget.set_contacts(other_users)
logger.info(f"Contact list updated: {len(other_users)} contacts")
def _on_state_changed(self, state: str, reason: str):
"""状态变化回调"""
@ -384,6 +403,18 @@ class P2PChatGUI(QObject):
self.main_window._statusbar.showMessage(f"正在呼叫...")
# TODO: 实现语音通话
def _on_contact_selected(self, user_id: str):
"""联系人选中回调"""
self._current_chat_peer = user_id
logger.debug(f"Contact selected: {user_id}")
def _on_contact_double_clicked(self, user_id: str):
"""联系人双击回调 - 打开聊天"""
self._current_chat_peer = user_id
logger.info(f"Opening chat with: {user_id}")
# TODO: 打开聊天窗口
self.main_window._statusbar.showMessage(f"{user_id} 聊天", 3000)
def cleanup(self):
"""清理资源"""
logger.info("Cleaning up resources...")

Loading…
Cancel
Save