When joining a room show already sent chat messages
This commit is contained in:
@@ -190,22 +190,31 @@ class VlcSyncApp(QMainWindow):
|
|||||||
|
|
||||||
self.room_widget.setup_room(self.room_code, self.username, self.local_file_name, self.local_file_path, start_time_s)
|
self.room_widget.setup_room(self.room_code, self.username, self.local_file_name, self.local_file_path, start_time_s)
|
||||||
|
|
||||||
|
chat_history = msg.get("chatHistory", [])
|
||||||
|
if chat_history:
|
||||||
|
for chat in chat_history:
|
||||||
|
self.room_widget.add_chat_message(chat.get("username", "Unknown"), chat.get("message", ""), chat.get("timestamp", 0))
|
||||||
|
|
||||||
users = msg.get("users", [])
|
users = msg.get("users", [])
|
||||||
if users:
|
if users:
|
||||||
self.room_widget.update_users(users)
|
self.room_widget.update_users(users)
|
||||||
|
|
||||||
if state:
|
if state:
|
||||||
self.room_widget.handle_sync_event(state)
|
self.room_widget.handle_sync_event(state)
|
||||||
|
|
||||||
chat_history = msg.get("chatHistory", [])
|
self.room_widget.add_system_message("Welcome to the room! 👋")
|
||||||
if chat_history:
|
|
||||||
for chat in chat_history:
|
|
||||||
self.room_widget.add_chat_message(chat.get("username", "Unknown"), chat.get("message", ""), chat.get("timestamp", 0))
|
|
||||||
|
|
||||||
def on_room_rejoined(self, msg: dict):
|
def on_room_rejoined(self, msg: dict):
|
||||||
self.room_widget.set_room_code_display(self.room_code)
|
self.room_widget.set_room_code_display(self.room_code)
|
||||||
self.room_widget.add_system_message("✅ Reconnected to the room.")
|
|
||||||
|
|
||||||
|
chat_history = msg.get("chatHistory", [])
|
||||||
|
if chat_history:
|
||||||
|
self.room_widget.clear_chat()
|
||||||
|
for chat in chat_history:
|
||||||
|
self.room_widget.add_chat_message(chat.get("username", "Unknown"), chat.get("message", ""), chat.get("timestamp", 0))
|
||||||
|
|
||||||
|
self.room_widget.add_system_message("✅ Reconnected to the room.")
|
||||||
|
|
||||||
users = msg.get("users", [])
|
users = msg.get("users", [])
|
||||||
if users:
|
if users:
|
||||||
self.room_widget.update_users(users)
|
self.room_widget.update_users(users)
|
||||||
|
|||||||
@@ -366,8 +366,6 @@ class RoomWidget(QWidget):
|
|||||||
self.chat_messages.setWidget(self.chat_content)
|
self.chat_messages.setWidget(self.chat_content)
|
||||||
self.chat_messages.toPlainText = self.toPlainText # For test compatibility
|
self.chat_messages.toPlainText = self.toPlainText # For test compatibility
|
||||||
|
|
||||||
# Initial welcome message
|
|
||||||
self.add_system_message("Welcome to the room! 👋")
|
|
||||||
|
|
||||||
chat_input_layout = QHBoxLayout()
|
chat_input_layout = QHBoxLayout()
|
||||||
self.chat_input = QLineEdit()
|
self.chat_input = QLineEdit()
|
||||||
@@ -443,7 +441,7 @@ class RoomWidget(QWidget):
|
|||||||
for i in reversed(range(self.chat_content_layout.count())):
|
for i in reversed(range(self.chat_content_layout.count())):
|
||||||
self.chat_content_layout.itemAt(i).widget().setParent(None)
|
self.chat_content_layout.itemAt(i).widget().setParent(None)
|
||||||
|
|
||||||
self.add_system_message("Welcome to the room! 👋")
|
|
||||||
self.current_users = []
|
self.current_users = []
|
||||||
self._is_first_user_update = True
|
self._is_first_user_update = True
|
||||||
|
|
||||||
@@ -906,6 +904,12 @@ class RoomWidget(QWidget):
|
|||||||
self.chat_content_layout.addWidget(msg)
|
self.chat_content_layout.addWidget(msg)
|
||||||
self._scroll_to_bottom()
|
self._scroll_to_bottom()
|
||||||
|
|
||||||
|
def clear_chat(self):
|
||||||
|
for i in reversed(range(self.chat_content_layout.count())):
|
||||||
|
item = self.chat_content_layout.itemAt(i)
|
||||||
|
if item.widget():
|
||||||
|
item.widget().setParent(None)
|
||||||
|
|
||||||
def send_chat(self):
|
def send_chat(self):
|
||||||
text = self.chat_input.text().strip()
|
text = self.chat_input.text().strip()
|
||||||
if not text:
|
if not text:
|
||||||
|
|||||||
@@ -235,6 +235,10 @@
|
|||||||
// Seamless reconnection — sync to server state
|
// Seamless reconnection — sync to server state
|
||||||
isReconnecting = false;
|
isReconnecting = false;
|
||||||
showConnectionStatus("reconnected");
|
showConnectionStatus("reconnected");
|
||||||
|
if (msg.chatHistory) {
|
||||||
|
chatMessages.innerHTML = "";
|
||||||
|
msg.chatHistory.forEach((m) => addChatMessage(m.username, m.message, m.timestamp));
|
||||||
|
}
|
||||||
updateUsers(msg.users);
|
updateUsers(msg.users);
|
||||||
if (msg.state) {
|
if (msg.state) {
|
||||||
applySync(msg.state);
|
applySync(msg.state);
|
||||||
|
|||||||
Reference in New Issue
Block a user