Clean code.
This commit is contained in:
@@ -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();
|
||||
@@ -81,53 +86,8 @@ public class ChatPageController {
|
||||
private ChatEntry currentChat;
|
||||
private UUID me;
|
||||
|
||||
private void initCurrentUserId() {
|
||||
try {
|
||||
String meStr = org.to.telegramfinalproject.Client.Session
|
||||
.currentUser.getString("internal_uuid");
|
||||
me = UUID.fromString(meStr);
|
||||
} catch (Exception ignore) {
|
||||
me = null;
|
||||
}
|
||||
}
|
||||
|
||||
//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";
|
||||
|
||||
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
|
||||
public void initialize() {
|
||||
|
||||
initCurrentUserId();
|
||||
|
||||
// Send button
|
||||
@@ -235,6 +195,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();
|
||||
@@ -424,7 +422,6 @@ public class ChatPageController {
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
private void renderMessages(org.json.JSONArray arr) {
|
||||
messageContainer.getChildren().clear();
|
||||
|
||||
@@ -465,8 +462,6 @@ public class ChatPageController {
|
||||
messageScrollPane.setVvalue(1.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void markAsRead(ChatEntry entry) {
|
||||
JSONObject readReq = new JSONObject();
|
||||
readReq.put("action", "mark_as_read");
|
||||
@@ -508,7 +503,4 @@ public class ChatPageController {
|
||||
|
||||
messageContainer.getChildren().add(row);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user