@@ -4,33 +4,39 @@ import ai.devchat.common.Log
44import ai.devchat.devchat.ActionHandler
55import ai.devchat.devchat.DevChatActionHandler
66import ai.devchat.devchat.DevChatActions
7+ import ai.devchat.idea.storage.ActiveConversation
78import com.alibaba.fastjson.JSONObject
89
910class LoadConversationRequestHandler (private val handler : DevChatActionHandler ) : ActionHandler {
1011 private var metadata: JSONObject ? = null
1112 private var payload: JSONObject ? = null
1213
13- private fun action (resMetadata : JSONObject , resPayload : JSONObject ) {
14+ private fun action (res : JSONObject ) {
1415 val topicHash = metadata!! .getString(" topicHash" )
15- val conversations = handler.devChat.logTopic(topicHash, null )
16- // remove request_tokens and response_tokens in the conversations object
17- for (i in conversations.indices) {
18- val conversation = conversations.getJSONObject(i)
19- conversation.remove(" request_tokens" )
20- conversation.remove(" response_tokens" )
16+ res[" reset" ] = true
17+ when {
18+ topicHash.isNullOrEmpty() -> ActiveConversation .reset()
19+ topicHash == ActiveConversation .topic -> res[" reset" ] = false
20+ else -> {
21+ val arr = handler.devChat.logTopic(topicHash, null )
22+ // remove request_tokens and response_tokens in the conversations object
23+ val messages = List <JSONObject >(arr.size){i ->
24+ val msg = arr.getJSONObject(i)
25+ msg.remove(" request_tokens" )
26+ msg.remove(" response_tokens" )
27+ msg
28+ }
29+ ActiveConversation .reset(topicHash, messages)
30+ }
2131 }
22- resMetadata[" status" ] = " success"
23- resMetadata[" error" ] = " "
24- resPayload[" conversations" ] = conversations
2532 }
2633
2734 override fun executeAction () {
2835 handler.handle(
2936 DevChatActions .LOAD_CONVERSATIONS_RESPONSE ,
3037 metadata!! .getString(" callback" ),
31- ) {resMetadata: JSONObject , resPayload: JSONObject ->
32- action(resMetadata, resPayload)
33- }
38+ ::action
39+ )
3440 }
3541
3642 override fun setMetadata (metadata : JSONObject ) {
0 commit comments