Skip to content

Commit

Permalink
Add route to search trend
Browse files Browse the repository at this point in the history
  • Loading branch information
zapek committed Nov 17, 2024
1 parent a032cd5 commit 6c68b15
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
@Service
public class FileTrendNotificationService extends NotificationService
{
public void receivedSearch(String keywords)
public void receivedSearch(String senderName, String keywords)
{
sendNotification(new FileTrendNotification(keywords));
sendNotification(new FileTrendNotification(senderName, keywords));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ public List<byte[]> receiveSearchRequest(byte[] query, int maxHits)
}

@Override
public void receiveSearchRequestString(String keywords)
public void receiveSearchRequestString(PeerConnection sender, String keywords)
{
fileTrendNotificationService.receivedSearch(keywords);
fileTrendNotificationService.receivedSearch(sender.getLocation().getProfile().getName(), keywords);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package io.xeres.app.xrs.service.status;

import io.xeres.app.database.DatabaseSession;
import io.xeres.app.database.DatabaseSessionManager;
import io.xeres.app.net.peer.PeerConnection;
import io.xeres.app.net.peer.PeerConnectionManager;
import io.xeres.app.service.LocationService;
Expand Down Expand Up @@ -51,15 +53,17 @@ public class StatusRsService extends RsService
private final PeerConnectionManager peerConnectionManager;
private final LocationService locationService;
private final AvailabilityNotificationService availabilityNotificationService;
private final DatabaseSessionManager databaseSessionManager;

private boolean locked;

public StatusRsService(RsServiceRegistry rsServiceRegistry, PeerConnectionManager peerConnectionManager, LocationService locationService, AvailabilityNotificationService availabilityNotificationService)
public StatusRsService(RsServiceRegistry rsServiceRegistry, PeerConnectionManager peerConnectionManager, LocationService locationService, AvailabilityNotificationService availabilityNotificationService, DatabaseSessionManager databaseSessionManager)
{
super(rsServiceRegistry);
this.peerConnectionManager = peerConnectionManager;
this.locationService = locationService;
this.availabilityNotificationService = availabilityNotificationService;
this.databaseSessionManager = databaseSessionManager;
}

@Override
Expand Down Expand Up @@ -129,11 +133,14 @@ public void changeAvailabilityAutomatically(Availability availability)
{
if (!locked && availability != this.availability)
{
var ownLocation = locationService.findOwnLocation().orElseThrow();
this.availability = availability;
locationService.setAvailability(ownLocation, availability);
availabilityNotificationService.changeAvailability(ownLocation, availability);
peerConnectionManager.doForAllPeers(peerConnection -> peerConnectionManager.writeItem(peerConnection, new StatusItem(toChatStatus(availability)), this), this);
try (var session = new DatabaseSession(databaseSessionManager))
{
var ownLocation = locationService.findOwnLocation().orElseThrow();
this.availability = availability;
locationService.setAvailability(ownLocation, availability);
availabilityNotificationService.changeAvailability(ownLocation, availability);
peerConnectionManager.doForAllPeers(peerConnection -> peerConnectionManager.writeItem(peerConnection, new StatusItem(toChatStatus(availability)), this), this);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public interface TurtleRsClient extends RsServiceSlave
*/
List<byte[]> receiveSearchRequest(byte[] query, int maxHits); // XXX: return a list of results (TurtleFileInfoV2.. actually it's generic stuff so service dependent)

void receiveSearchRequestString(String keywords); // XXX: experimental for now...
void receiveSearchRequestString(PeerConnection sender, String keywords); // XXX: experimental for now...

/**
* Called when receiving search results.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ private void handleSearchRequest(PeerConnection sender, TurtleSearchRequestItem
}

// XXX: experimental
turtleClients.forEach(turtleRsClient -> turtleRsClient.receiveSearchRequestString(item.getKeywords()));
turtleClients.forEach(turtleRsClient -> turtleRsClient.receiveSearchRequestString(sender, item.getKeywords()));

// Do not search further if enough has been sent back already.
if (searchRequest.isFull())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

import io.xeres.common.rest.notification.Notification;

public record FileTrendNotification(String keywords) implements Notification
public record FileTrendNotification(String senderName, String keywords) implements Notification
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public class FileTrendViewController implements Controller, TabActivation
// @FXML
// private TableColumn<TrendResult, Integer> tableHits;
//
// @FXML
// private TableColumn<TrendResult, String> tableFrom;
@FXML
private TableColumn<TrendResult, String> tableFrom;

@FXML
private TableColumn<TrendResult, String> tableTerms;
Expand All @@ -64,6 +64,7 @@ public FileTrendViewController(NotificationClient notificationClient)
public void initialize() throws IOException
{
tableTerms.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().keywords()));
tableFrom.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().senderName()));

setupFileTrendNotifications();
}
Expand All @@ -74,10 +75,10 @@ private void setupFileTrendNotifications()
.doOnError(UiUtils::showAlertError)
.doOnNext(sse -> Platform.runLater(() -> {
assert sse.data() != null;
trendTableView.getItems().add(new TrendResult(sse.data().keywords()));
trendTableView.getItems().add(new TrendResult(sse.data().keywords(), sse.data().senderName()));
if (trendTableView.getItems().size() > 255) // XXX: maybe not optimal...
{
trendTableView.getItems().removeFirst();
trendTableView.getItems().remove(0, 10);
}
}))
.subscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@

package io.xeres.ui.controller.file;

public record TrendResult(String keywords)
public record TrendResult(String keywords, String senderName)
{
}
8 changes: 3 additions & 5 deletions ui/src/main/resources/view/file/trend.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
-->

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.VBox?>
<VBox spacing="4.0" xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
Expand All @@ -39,8 +37,8 @@
</placeholder>
<columns>
<!--<TableColumn fx:id="tableHits" prefWidth="60.0" text="Hits"/>-->
<!--<TableColumn fx:id="tableFrom" prefWidth="120.0" text="From"/>-->
<TableColumn fx:id="tableTerms" text="Terms"/>
<TableColumn fx:id="tableTerms" minWidth="100.0" prefWidth="180.0" text="Terms"/>
<TableColumn fx:id="tableFrom" prefWidth="120.0" text="From"/>
</columns>
</TableView>
</VBox>

0 comments on commit 6c68b15

Please sign in to comment.