Profile logic for UI

This commit is contained in:
2025-09-04 20:45:38 +03:30
parent 89e2033ac2
commit 9c61b27004
11 changed files with 674 additions and 115 deletions
@@ -30,6 +30,8 @@ import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import static org.to.telegramfinalproject.Client.Session.currentChatId;
public class ChatPageController {
// ===== messages area =====
@@ -2354,6 +2356,39 @@ private void addBubble(
}
}
// ChatPageController.java
public void onChatAvatarUpdated(UUID chatId, String newUrl) {
// اگه چت فعلی چیز دیگریه، کاری نکن
if (currentChat == null || chatId == null || newUrl == null || newUrl.isBlank()) return;
if (!currentChat.getId().equals(chatId)) return;
// اگر از نخ غیر JavaFX صدا زده شد، امنش کنیم
if (!Platform.isFxApplicationThread()) {
Platform.runLater(() -> onChatAvatarUpdated(chatId, newUrl));
return;
}
// State داخلی entry را هم آپدیت کن
currentChat.setImageUrl(newUrl);
// آواتار هدر را ست کن (با resolver خودت)
try {
Image im = org.to.telegramfinalproject.Client.AvatarLocalResolver.load(newUrl);
if (im != null) {
userAvatar.setImage(im);
} else {
// fallback اگر لود نشد
setDefaultHeaderAvatarByType(currentChat.getType());
}
} catch (Exception ignore) {
setDefaultHeaderAvatarByType(currentChat.getType());
}
// مطمئن شو همچنان دایره‌ایه
try { AvatarFX.circleClip(userAvatar, 36); } catch (Throwable ignored) {}
}
private static final class ForwardTarget {