Fix desktop chat wrapping, character rendering, and unread alerts
This commit is contained in:
@@ -45,6 +45,8 @@ class RoomWidget(QWidget):
|
||||
self.popout_window = None
|
||||
|
||||
self._setup_ui()
|
||||
self._unread_messages = 0
|
||||
QApplication.instance().focusChanged.connect(self._on_chat_focus_changed)
|
||||
|
||||
def _setup_ui(self):
|
||||
layout = QVBoxLayout(self)
|
||||
@@ -174,7 +176,7 @@ class RoomWidget(QWidget):
|
||||
self.chat_container.setMaximumWidth(500)
|
||||
chat_layout = QVBoxLayout(self.chat_container)
|
||||
|
||||
chat_header = QLabel("Live Chat")
|
||||
chat_header = self.chat_header = QLabel("Live Chat")
|
||||
chat_header.setObjectName("chatHeader")
|
||||
|
||||
self.popout_btn = QPushButton("↗")
|
||||
@@ -323,6 +325,7 @@ class RoomWidget(QWidget):
|
||||
self.room_file_badge.setText(f"📄 {file_name}")
|
||||
|
||||
# Clear chat
|
||||
self._clear_chat_alert()
|
||||
for i in reversed(range(self.chat_content_layout.count())):
|
||||
self.chat_content_layout.itemAt(i).widget().setParent(None)
|
||||
|
||||
@@ -335,6 +338,7 @@ class RoomWidget(QWidget):
|
||||
self.vlc_player.set_volume(self.volume_slider.value())
|
||||
|
||||
def cleanup(self):
|
||||
self._clear_chat_alert()
|
||||
self.vlc_player.stop()
|
||||
self.current_users = []
|
||||
self._is_first_user_update = True
|
||||
@@ -723,13 +727,20 @@ class RoomWidget(QWidget):
|
||||
time_str = dt.strftime("%I:%M %p")
|
||||
|
||||
safe_text = html.escape(text)
|
||||
safe_author = html.escape(author)
|
||||
|
||||
|
||||
# Regex to find timestamps like 1:23 or 01:23:45
|
||||
pattern = r'\b(\d{1,2}:\d{2}(?::\d{2})?)\b'
|
||||
linked_text = re.sub(pattern, r'<a href="seek:\1" style="color: #66b3ff; text-decoration: none;">\1</a>', safe_text)
|
||||
linked_text = linked_text.replace('\n', '<br>')
|
||||
|
||||
is_self = author == self.username
|
||||
if not is_self and not self._chat_has_focus():
|
||||
self._unread_messages += 1
|
||||
self.chat_header.setText(f"Live Chat • {self._unread_messages} new")
|
||||
self.chat_toggle_btn.setText("💬•")
|
||||
self.chat_toggle_btn.setToolTip(f"{self._unread_messages} new chat messages")
|
||||
self.chat_toggle_btn.setStyleSheet("color: #66b3ff; border: 1px solid #66b3ff; border-radius: 6px;")
|
||||
QApplication.alert(self.chat_container.window(), 3000)
|
||||
|
||||
# Auto-extract tags added by users directly via /tag command
|
||||
# We look for the pattern generated by /tag: "MM:SS tag text"
|
||||
@@ -742,6 +753,24 @@ class RoomWidget(QWidget):
|
||||
bubble = ChatBubble(author, linked_text, time_str, is_self, self._handle_link_from_bubble)
|
||||
self.chat_content_layout.addWidget(bubble)
|
||||
self._scroll_to_bottom()
|
||||
|
||||
def _chat_has_focus(self):
|
||||
focus = QApplication.focusWidget()
|
||||
return (self.chat_container.isVisible()
|
||||
and self.chat_container.window().isActiveWindow()
|
||||
and focus is not None
|
||||
and (focus is self.chat_container or self.chat_container.isAncestorOf(focus)))
|
||||
|
||||
def _on_chat_focus_changed(self, old, new):
|
||||
if self._chat_has_focus():
|
||||
self._clear_chat_alert()
|
||||
|
||||
def _clear_chat_alert(self):
|
||||
self._unread_messages = 0
|
||||
self.chat_header.setText("Live Chat")
|
||||
self.chat_toggle_btn.setText("💬")
|
||||
self.chat_toggle_btn.setToolTip("Toggle Chat")
|
||||
self.chat_toggle_btn.setStyleSheet("")
|
||||
|
||||
def _handle_link_from_bubble(self, url_str):
|
||||
if url_str.startswith("seek:"):
|
||||
@@ -782,6 +811,7 @@ class RoomWidget(QWidget):
|
||||
self._scroll_to_bottom()
|
||||
|
||||
def clear_chat(self):
|
||||
self._clear_chat_alert()
|
||||
for i in reversed(range(self.chat_content_layout.count())):
|
||||
item = self.chat_content_layout.itemAt(i)
|
||||
if item.widget():
|
||||
|
||||
Reference in New Issue
Block a user