When joining a room show already sent chat messages

This commit is contained in:
Peter Stockings
2026-03-09 20:43:46 +11:00
parent 42f7ee7f12
commit e2edd296fc
3 changed files with 26 additions and 9 deletions

View File

@@ -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)
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", [])
if users:
self.room_widget.update_users(users)
if state:
self.room_widget.handle_sync_event(state)
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))
self.room_widget.add_system_message("Welcome to the room! 👋")
def on_room_rejoined(self, msg: dict):
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", [])
if users:
self.room_widget.update_users(users)

View File

@@ -366,8 +366,6 @@ class RoomWidget(QWidget):
self.chat_messages.setWidget(self.chat_content)
self.chat_messages.toPlainText = self.toPlainText # For test compatibility
# Initial welcome message
self.add_system_message("Welcome to the room! 👋")
chat_input_layout = QHBoxLayout()
self.chat_input = QLineEdit()
@@ -443,7 +441,7 @@ class RoomWidget(QWidget):
for i in reversed(range(self.chat_content_layout.count())):
self.chat_content_layout.itemAt(i).widget().setParent(None)
self.add_system_message("Welcome to the room! 👋")
self.current_users = []
self._is_first_user_update = True
@@ -906,6 +904,12 @@ class RoomWidget(QWidget):
self.chat_content_layout.addWidget(msg)
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):
text = self.chat_input.text().strip()
if not text:

View File

@@ -235,6 +235,10 @@
// Seamless reconnection — sync to server state
isReconnecting = false;
showConnectionStatus("reconnected");
if (msg.chatHistory) {
chatMessages.innerHTML = "";
msg.chatHistory.forEach((m) => addChatMessage(m.username, m.message, m.timestamp));
}
updateUsers(msg.users);
if (msg.state) {
applySync(msg.state);