mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-07 12:24:58 +10:00
retain chat history when saving to a new file name
This commit is contained in:
@@ -51,4 +51,8 @@ public interface IChatbotAPI {
|
||||
|
||||
List<ChatMessageEntity> getChatHistory(@ParamName("username") String username, @ParamName("token") String token,
|
||||
@ParamName("machineId") String machineId, @ParamName("project") String project);
|
||||
|
||||
String updateChatProject(@ParamName("username") String username, @ParamName("token") String token,
|
||||
@ParamName("machineId") String machineId, @ParamName("project") String project,
|
||||
@ParamName("newProject") String newProject);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,9 @@ import com.diyfever.httpproxy.ProxyFactory;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.simplemq.IMessageListener;
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
@@ -68,8 +70,37 @@ public class ChatbotService {
|
||||
|
||||
private IChatbotAPI service;
|
||||
|
||||
private String currentProjectName;
|
||||
|
||||
public ChatbotService(IPlugInPort plugInPort) {
|
||||
this.plugInPort = plugInPort;
|
||||
this.plugInPort.getMessageDispatcher().registerListener(new IMessageListener<EventType>() {
|
||||
|
||||
|
||||
@Override
|
||||
public EnumSet<EventType> getSubscribedEventTypes() {
|
||||
return EnumSet.of(EventType.PROJECT_LOADED, EventType.FILE_STATUS_CHANGED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processMessage(EventType eventType, Object... objects) {
|
||||
if (eventType == EventType.PROJECT_LOADED) {
|
||||
ChatbotService.this.currentProjectName = extractFileName((String)objects[2]);
|
||||
} else if (eventType == EventType.FILE_STATUS_CHANGED) {
|
||||
String newProjectName = extractFileName((String)objects[0]);
|
||||
if (!Objects.equals(ChatbotService.this.currentProjectName, newProjectName)) {
|
||||
if (plugInPort.getCloudService().isLoggedIn()) {
|
||||
LOG.info("Migrating project chat history from " + ChatbotService.this.currentProjectName + " to " + newProjectName);
|
||||
getService().updateChatProject(plugInPort.getCloudService().getCurrentUsername(),
|
||||
plugInPort.getCloudService().getCurrentToken(),
|
||||
plugInPort.getCloudService().getMachineId(),
|
||||
ChatbotService.this.currentProjectName, newProjectName);
|
||||
}
|
||||
ChatbotService.this.currentProjectName = newProjectName;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private IChatbotAPI getService() {
|
||||
|
||||
@@ -261,6 +261,10 @@
|
||||
<releaseDate>2025-03-27 00:00:00.000 CET</releaseDate>
|
||||
<name></name>
|
||||
<changes>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>When saving a project to the new file, retain all the AI Assistant chat history for the new project file</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Confirmation dialog before deleting AI Assistant chat history</description>
|
||||
|
||||
@@ -64,7 +64,7 @@ public class ChatbotPane extends JPanel {
|
||||
super();
|
||||
this.swingUI = swingUI;
|
||||
this.plugInPort = plugInPort;
|
||||
this.chatbotService = new ChatbotService(plugInPort);
|
||||
this.chatbotService = plugInPort.getChatbotService();
|
||||
setName("AI Assistant");
|
||||
|
||||
// Set panel background color
|
||||
|
||||
@@ -58,8 +58,6 @@ public class ChatbotPlugin implements IPlugIn {
|
||||
switch (eventType) {
|
||||
case FILE_STATUS_CHANGED:
|
||||
case PROJECT_LOADED:
|
||||
getChatbotPane().refreshChat(null);
|
||||
break;
|
||||
case CLOUD_LOGGED_IN:
|
||||
case CLOUD_LOGGED_OUT:
|
||||
SubscriptionEntity subscriptionInfo = null;
|
||||
|
||||
Reference in New Issue
Block a user