Skip to content

Commit

Permalink
Move ChatHistoryService to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Sep 8, 2024
1 parent bbcf36a commit 590fe41
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jabref.logic.ai.chatting.chathistory;
package org.jabref.gui.ai.chatting.chathistory;

import java.util.Comparator;
import java.util.HashSet;
Expand All @@ -11,9 +11,13 @@
import javafx.collections.ObservableList;

import org.jabref.gui.StateManager;
import org.jabref.logic.ai.chatting.chathistory.ChatHistoryStorage;
import org.jabref.logic.ai.chatting.chathistory.storages.MVStoreChatHistoryStorage;
import org.jabref.logic.ai.util.CitationKeyCheck;
import org.jabref.logic.citationkeypattern.CitationKeyGenerator;
import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences;
import org.jabref.logic.util.Directories;
import org.jabref.logic.util.NotificationService;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.event.FieldChangedEvent;
Expand All @@ -29,7 +33,8 @@

/**
* Main class for getting and storing chat history for entries and groups.
* Use this class in the logic and UI.
* Use this class <s>in logic and</s> UI.
* It currently resides in the UI package because it relies on the {@link StateManager} to get the open databases and to find the correct {@link BibDatabaseContext} based on an entry.
* <p>
* The returned chat history is a {@link ObservableList}. So chat history exists for every possible
* {@link BibEntry} and {@link AbstractGroup}. The chat history is stored in runtime.
Expand All @@ -51,6 +56,8 @@
public class ChatHistoryService implements AutoCloseable {
private static final Logger LOGGER = LoggerFactory.getLogger(ChatHistoryService.class);

private static final String CHAT_HISTORY_FILE_NAME = "chat-histories.mv";

private final StateManager stateManager = Injector.instantiateModelOrService(StateManager.class);

private final CitationKeyPatternPreferences citationKeyPatternPreferences;
Expand All @@ -72,6 +79,12 @@ private record ChatHistoryManagementRecord(Optional<BibDatabaseContext> bibDatab
return o1 == o2 ? 0 : o1.getGroup().getName().compareTo(o2.getGroup().getName());
});

public ChatHistoryService(CitationKeyPatternPreferences citationKeyPatternPreferences, NotificationService notificationService) {
this.citationKeyPatternPreferences = citationKeyPatternPreferences;
this.implementation = new MVStoreChatHistoryStorage(Directories.getAiFilesDirectory().resolve(CHAT_HISTORY_FILE_NAME), notificationService);
configureHistoryTransfer();
}

public ChatHistoryService(CitationKeyPatternPreferences citationKeyPatternPreferences,
ChatHistoryStorage implementation) {
this.citationKeyPatternPreferences = citationKeyPatternPreferences;
Expand Down

0 comments on commit 590fe41

Please sign in to comment.