Merge remote-tracking branch 'origin/Connection-UI' into Connection-UI

# Conflicts:
#	src/main/java/org/to/telegramfinalproject/UI/ChatPageController.java
This commit is contained in:
2025-08-29 21:13:06 +03:30
4 changed files with 51 additions and 16 deletions
@@ -72,6 +72,11 @@ public class ChatPageController {
@FXML
private ImageView sendIcon;
// ===== Time formatter for messages =====
private static final DateTimeFormatter FMT_HHMM = DateTimeFormatter.ofPattern("HH:mm");
private static final DateTimeFormatter FMT_DATE_TIME = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm");
private static final String YESTERDAY_LABEL = "Yesterday";
// ===== state =====
private String chatName;
private final ThemeManager themeManager = ThemeManager.getInstance();
@@ -149,7 +154,6 @@ public class ChatPageController {
@FXML
public void initialize() {
initCurrentUserId();
// Send button
@@ -257,6 +261,44 @@ public class ChatPageController {
themeManager.darkModeProperty().addListener((o, oldVal, isDark) -> syncIconsWithTheme());
}
private void initCurrentUserId() {
try {
String meStr = org.to.telegramfinalproject.Client.Session
.currentUser.getString("internal_uuid");
me = UUID.fromString(meStr);
} catch (Exception ignore) {
me = null;
}
}
private String formatWhen(LocalDateTime ts) {
if (ts == null) return "";
LocalDate today = LocalDate.now();
LocalDate d = ts.toLocalDate();
if (d.isEqual(today)) {
return FMT_HHMM.format(ts);
} else if (d.isEqual(today.minusDays(1))) {
return YESTERDAY_LABEL + " " + FMT_HHMM.format(ts);
} else {
return FMT_DATE_TIME.format(ts);
}
}
/** ISO → LocalDateTime (با پشتیبانی از Offset/Z) */
private LocalDateTime parseWhen(String iso) {
if (iso == null || iso.isEmpty()) return null;
try {
return OffsetDateTime.parse(iso).toLocalDateTime();
} catch (Exception ignore) {
try {
return LocalDateTime.parse(iso);
} catch (Exception e) {
return null;
}
}
}
@FXML
private void openSearchPanel() {
MainController.getInstance().showSearchPanel();
@@ -50,6 +50,12 @@ public class MainController {
@FXML private ImageView menuIcon;
private SidebarMenuController sidebarController; //save sidebar controller
// === Time formatter for messages ===
private static final java.time.format.DateTimeFormatter FMT_HHMM =
java.time.format.DateTimeFormatter.ofPattern("HH:mm");
private static final java.time.format.DateTimeFormatter FMT_DATE_TIME =
java.time.format.DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm");
private static final String YESTERDAY_LABEL = "Yesterday";
// === STATE ===
private static MainController instance;
@@ -174,13 +180,6 @@ public class MainController {
//
// }
private static final java.time.format.DateTimeFormatter FMT_HHMM =
java.time.format.DateTimeFormatter.ofPattern("HH:mm");
private static final java.time.format.DateTimeFormatter FMT_DATE_TIME =
java.time.format.DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm");
private static final String YESTERDAY_LABEL = "Yesterday";
// ...
private String formatChatTime(java.time.LocalDateTime ts) {
if (ts == null) return "";
@@ -198,9 +197,6 @@ public class MainController {
}
}
private void populateChatListFromSession() {
chatListContainer.getChildren().clear();
@@ -216,7 +212,6 @@ public class MainController {
}
}
// private void addChatNode(ChatEntry chat ) {
// try {
// FXMLLoader fx = new FXMLLoader(getClass().getResource(
@@ -260,7 +255,6 @@ public class MainController {
}
}
private String mapTypeToLabel(String t) {
switch (t.toUpperCase()) {
case "IMAGE": return "[Image]";
@@ -271,7 +265,6 @@ public class MainController {
}
}
// private void addChat(String name, String lastMsg, String time, int unread) {
// try {
// FXMLLoader loader = new FXMLLoader(getClass().getResource("/org/to/telegramfinalproject/Fxml/chat_item.fxml"));
@@ -197,7 +197,7 @@ public class SidebarMenuController {
String img = user.optString("image_url", "");
Image pic = tryLoadImage(img);
if (pic == null) {
pic = loadImage("/org/to/telegramfinalproject/Avatars/profile.png");
pic = loadImage("/org/to/telegramfinalproject/Avatars/default_profile.png");
}
if (pic != null) profileImage.setImage(pic);
}
@@ -45,7 +45,7 @@ import java.io.IOException;
public class TelegramApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
// اول intro.fxml
// First: intro.fxml
FXMLLoader fx = new FXMLLoader(
TelegramApplication.class.getResource("/org/to/telegramfinalproject/Fxml/intro.fxml"));
Scene scene = new Scene(fx.load(), 1480, 820);