Last seen & profile in chat fixed.

This commit is contained in:
Asal Lotfi
2025-08-31 03:17:27 +03:30
parent 186d890e7d
commit bdd9d03128
4 changed files with 129 additions and 95 deletions
@@ -2778,6 +2778,35 @@ public class ClientHandler implements Runnable {
break;
}
case "get_other_user_status": {
try {
String userIdStr = requestJson.getString("user_id");
UUID user_id = UUID.fromString(userIdStr);
String lastSeenStr = userDatabase.getLastSeen(user_id); // returns ISO string?
JSONObject data = new JSONObject();
if (lastSeenStr != null && !"Unknown".equals(lastSeenStr)) {
// parse string to time
LocalDateTime lastSeen = LocalDateTime.parse(lastSeenStr);
long diffMillis = java.time.Duration.between(lastSeen, LocalDateTime.now()).toMillis();
boolean online = diffMillis <= 120_000;
data.put("online", online);
data.put("last_seen", lastSeen.toString());
response = new ResponseModel("success", "Status fetched.", data);
} else {
response = new ResponseModel("error", "User not found.");
}
} catch (Exception e) {
e.printStackTrace();
response = new ResponseModel("error", "Failed to fetch status.");
}
break;
}
default:
response = new ResponseModel("error", "Unknown action: " + action);