desktop chat now shows images

This commit is contained in:
Alex
2026-04-15 00:00:17 -06:00
parent be697f080e
commit 017ef65b5a
2 changed files with 35 additions and 4 deletions

View File

@@ -14,6 +14,7 @@ public class MessageResponse {
private Boolean isRead;
private String attachmentName;
private String attachmentUrl;
private String attachmentMimeType;
public MessageResponse() {
}
@@ -105,4 +106,12 @@ public class MessageResponse {
public void setAttachmentUrl(String attachmentUrl) {
this.attachmentUrl = attachmentUrl;
}
public String getAttachmentMimeType() {
return attachmentMimeType;
}
public void setAttachmentMimeType(String attachmentMimeType) {
this.attachmentMimeType = attachmentMimeType;
}
}

View File

@@ -19,6 +19,7 @@ import javafx.scene.layout.VBox;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Circle;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import org.example.petshopdesktop.api.ChatRealtimeClient;
import org.example.petshopdesktop.api.dto.chat.ConversationResponse;
import org.example.petshopdesktop.api.dto.chat.MessageRequest;
@@ -539,11 +540,32 @@ public class ChatController {
bubble.getChildren().add(content);
}
if (message.getAttachmentName() != null && !message.getAttachmentName().isBlank()) {
String mimeType = message.getAttachmentMimeType();
boolean isImage = mimeType != null && mimeType.startsWith("image/");
if (isImage && message.getId() != null) {
ImageView imageView = new ImageView();
imageView.setFitWidth(280);
imageView.setFitHeight(280);
imageView.setPreserveRatio(true);
imageView.setSmooth(true);
bubble.getChildren().add(imageView);
String attachmentPath = "/api/v1/chat/messages/" + message.getId() + "/attachment";
new Thread(() -> {
try {
byte[] bytes = ApiClient.getInstance().getBytes(attachmentPath);
Image img = new Image(new java.io.ByteArrayInputStream(bytes));
if (!img.isError()) {
Platform.runLater(() -> imageView.setImage(img));
}
} catch (Exception ignored) {}
}).start();
} else {
Label attachmentLabel = new Label("\uD83D\uDCCE " + message.getAttachmentName());
attachmentLabel.setStyle("-fx-text-fill: " + (mine ? "#dbeafe" : "#475569") + "; -fx-font-size: 12px;");
attachmentLabel.setWrapText(true);
bubble.getChildren().add(attachmentLabel);
}
}
bubble.getChildren().add(timestamp);
bubble.setMaxWidth(420);