66import ai .devchat .devchat .ActionHandler ;
77import ai .devchat .devchat .DevChatActionHandler ;
88import ai .devchat .devchat .DevChatActions ;
9+ import ai .devchat .idea .storage .DeletedTopicsState ;
910
1011import com .alibaba .fastjson .JSONArray ;
1112import com .alibaba .fastjson .JSONObject ;
1213
14+ import java .util .List ;
15+
1316public class ListTopicsRequestHandler implements ActionHandler {
1417 private JSONObject metadata ;
1518 private JSONObject payload ;
@@ -26,43 +29,58 @@ public void executeAction() {
2629 String callbackFunc = metadata .getString ("callback" );
2730 try {
2831 DevChatWrapper devchatWrapper = new DevChatWrapper (DevChatPathUtil .getDevchatBinPath ());
29- /* topics format:
30- [
31- {
32- "root_prompt": {
33- "user": "Daniel Hu <tao.hu@merico.dev>",
34- "date": 1698828624,
35- "context": [
36- {
37- "content": "{\"languageId\":\"python\",\"path\":\"a.py\",\"startLine\":0,\"content\":\"adkfjj\\n\"}",
38- "role": "system"
39- }
40- ],
41- "request": "hello",
42- "responses": [
43- "Hi there! How can I assist you with Python today?"
44- ],
45- "request_tokens": 46,
46- "response_tokens": 22,
47- "hash": "596cf7c60a936e33409c71b67ba7f9903886bbeb7c7d2aacf6d1556b0831f04b",
48- "parent": null
49- },
50- "latest_time": 1698828867,
51- "title": null,
52- "hidden": false
53- }
54- ]
32+ /*
33+ * topics format:
34+ * [
35+ * {
36+ * "root_prompt": {
37+ * "user": "Daniel Hu <tao.hu@merico.dev>",
38+ * "date": 1698828624,
39+ * "context": [
40+ * {
41+ * "content":
42+ * "{\"languageId\":\"python\",\"path\":\"a.py\",\"startLine\":0,\"content\":\"adkfjj\\n\"}",
43+ * "role": "system"
44+ * }
45+ * ],
46+ * "request": "hello",
47+ * "responses": [
48+ * "Hi there! How can I assist you with Python today?"
49+ * ],
50+ * "request_tokens": 46,
51+ * "response_tokens": 22,
52+ * "hash": "596cf7c60a936e33409c71b67ba7f9903886bbeb7c7d2aacf6d1556b0831f04b",
53+ * "parent": null
54+ * },
55+ * "latest_time": 1698828867,
56+ * "title": null,
57+ * "hidden": false
58+ * }
59+ * ]
5560 */
5661 JSONArray topics = devchatWrapper .listTopics ();
57- // remove request_tokens and response_tokens in the topics object, then update title field.
62+
63+ // Get deleted topics hash list
64+ DeletedTopicsState deletedTopicsState = DeletedTopicsState .getInstance ();
65+ List <String > deletedTopicHashes = deletedTopicsState .deletedTopicHashes ;
66+
67+ // Filter out deleted topics
68+ JSONArray filteredTopics = new JSONArray ();
69+ // remove request_tokens and response_tokens in the topics object, then update
70+ // title field.
5871 for (int i = 0 ; i < topics .size (); i ++) {
5972 JSONObject topic = topics .getJSONObject (i );
60- topic .remove ("latest_time" );
61- topic .remove ("hidden" );
62- // set title = root_prompt.request + "-" + root_prompt.responses[0]
6373 JSONObject rootPrompt = topic .getJSONObject ("root_prompt" );
64- String title = rootPrompt .getString ("request" ) + "-" + rootPrompt .getJSONArray ("responses" ).getString (0 );
65- rootPrompt .put ("title" , title );
74+ String topicHash = rootPrompt .getString ("hash" );
75+
76+ if (!deletedTopicHashes .contains (topicHash )) {
77+ // set title = root_prompt.request + "-" + root_prompt.responses[0]
78+ String title = rootPrompt .getString ("request" ) + "-"
79+ + rootPrompt .getJSONArray ("responses" ).getString (0 );
80+ rootPrompt .put ("title" , title );
81+
82+ filteredTopics .add (topic );
83+ }
6684 }
6785
6886 devChatActionHandler .sendResponse (DevChatActions .LIST_TOPICS_RESPONSE , callbackFunc , (metadata , payload ) -> {
0 commit comments