Work on connection to search bar

This commit is contained in:
2025-08-29 23:26:06 +03:30
parent 2bae5a5b78
commit 60338fec52
2 changed files with 375 additions and 16 deletions
@@ -30,6 +30,11 @@ public class ActionHandler {
//use for UI
private volatile String lastStatus = "error"; // success | error
private volatile String lastMessage = "";
// ===== UI hook for search results =====
public String getLastStatus() { return lastStatus; }
public String getLastMessage() { return lastMessage; }
@@ -37,7 +42,6 @@ public class ActionHandler {
private void handleRealTime(JSONObject json) throws IOException {
IncomingMessageListener listener = new IncomingMessageListener(this.in);
listener.handleRealTimeEvent (json);
@@ -141,6 +145,18 @@ public class ActionHandler {
send(model.toJson());
}
public void searchUI(String keyword) {
if (Session.currentUser == null || !Session.currentUser.has("user_id")) {
System.out.println("You must be logged in to search.");
return;
}
String userId = Session.currentUser.getString("user_id");
SearchRequestModel model = new SearchRequestModel("search", keyword, userId);
send(model.toJson());
}
public void searchInUsers(){
System.out.println("Enter keyword to search: ");
@@ -664,6 +680,8 @@ public class ActionHandler {
}
break;
case "search" :
JSONArray results = response.getJSONObject("data").getJSONArray("results");
if (results.isEmpty()) {