stabilize desktop chat

This commit is contained in:
2026-04-07 09:38:17 -06:00
parent c776c579ab
commit 27871d96f5

View File

@@ -5,7 +5,6 @@ import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.ListCell; import javafx.scene.control.ListCell;
import javafx.scene.control.ListView; import javafx.scene.control.ListView;
@@ -124,6 +123,7 @@ public class ChatController {
@FXML @FXML
void btnSendClicked() { void btnSendClicked() {
try {
if (selectedConversation == null) { if (selectedConversation == null) {
lblChatStatus.setText("Select a conversation"); lblChatStatus.setText("Select a conversation");
return; return;
@@ -139,6 +139,13 @@ public class ChatController {
if (!sent) { if (!sent) {
sendMessageFallback(selectedConversation.getId(), content); sendMessageFallback(selectedConversation.getId(), content);
} }
} catch (Exception e) {
ActivityLogger.getInstance().logException(
"ChatController.btnSendClicked",
e,
"Sending chat message");
lblChatStatus.setText("Chat send failed");
}
} }
private void loadCustomers() { private void loadCustomers() {
@@ -224,17 +231,31 @@ public class ChatController {
private void renderMessages(List<MessageResponse> messages) { private void renderMessages(List<MessageResponse> messages) {
vbMessages.getChildren().clear(); vbMessages.getChildren().clear();
for (MessageResponse message : messages) { for (MessageResponse message : messages) {
try {
vbMessages.getChildren().add(createMessageBubble(message)); vbMessages.getChildren().add(createMessageBubble(message));
} catch (Exception e) {
ActivityLogger.getInstance().logException(
"ChatController.renderMessages",
e,
"Rendering chat message");
}
} }
scrollMessagesToBottom(); scrollMessagesToBottom();
} }
private void appendMessageIfSelected(MessageResponse message) { private void appendMessageIfSelected(MessageResponse message) {
try {
upsertConversationForMessage(message); upsertConversationForMessage(message);
if (selectedConversation != null && selectedConversation.getId().equals(message.getConversationId())) { if (selectedConversation != null && selectedConversation.getId().equals(message.getConversationId())) {
vbMessages.getChildren().add(createMessageBubble(message)); vbMessages.getChildren().add(createMessageBubble(message));
scrollMessagesToBottom(); scrollMessagesToBottom();
} }
} catch (Exception e) {
ActivityLogger.getInstance().logException(
"ChatController.appendMessageIfSelected",
e,
"Appending chat message");
}
} }
private void upsertConversation(ConversationResponse conversation) { private void upsertConversation(ConversationResponse conversation) {
@@ -306,10 +327,9 @@ public class ChatController {
if (message.getAttachmentSizeBytes() != null && message.getAttachmentSizeBytes() > 0) { if (message.getAttachmentSizeBytes() != null && message.getAttachmentSizeBytes() > 0) {
attachmentLabel = attachmentLabel + " (" + formatSize(message.getAttachmentSizeBytes()) + ")"; attachmentLabel = attachmentLabel + " (" + formatSize(message.getAttachmentSizeBytes()) + ")";
} }
Hyperlink attachment = new Hyperlink(attachmentLabel); Label attachment = new Label(attachmentLabel);
attachment.setWrapText(true); attachment.setWrapText(true);
attachment.setOnAction(event -> openAttachment(message.getAttachmentUrl())); attachment.setStyle("-fx-text-fill: " + (mine ? "#dbeafe" : "#0f766e") + "; -fx-underline: true;");
attachment.setStyle("-fx-text-fill: " + (mine ? "#dbeafe" : "#0f766e") + ";");
bubble.getChildren().add(attachment); bubble.getChildren().add(attachment);
} }
@@ -368,18 +388,6 @@ public class ChatController {
private void scrollMessagesToBottom() { private void scrollMessagesToBottom() {
Platform.runLater(() -> spMessages.setVvalue(1.0)); Platform.runLater(() -> spMessages.setVvalue(1.0));
} }
private void openAttachment(String url) {
try {
java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
} catch (Exception e) {
ActivityLogger.getInstance().logException(
"ChatController.openAttachment",
e,
"Opening chat attachment");
}
}
private String formatSize(Long bytes) { private String formatSize(Long bytes) {
if (bytes == null || bytes <= 0) { if (bytes == null || bytes <= 0) {
return ""; return "";