Skip to content

Commit

Permalink
Implement loadHistoryMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
pplam committed Dec 5, 2023
1 parent 70590bc commit c403019
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/kotlin/ai/devchat/devchat/ActionHandlerFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ActionHandlerFactory {
put(DevChatActions.SET_OR_UPDATE_KEY_REQUEST, SetOrUpdateKeyRequestHandler::class)
put(DevChatActions.LIST_COMMANDS_REQUEST, ListCommandsRequestHandler::class)
put(DevChatActions.LOAD_CONVERSATIONS_REQUEST, LoadConversationRequestHandler::class)
put(DevChatActions.LOAD_HISTORY_MESSAGES_REQUEST, LoadHistoryMessagesRequestHandler::class)
put(DevChatActions.LIST_TOPICS_REQUEST, ListTopicsRequestHandler::class)
put(DevChatActions.INSERT_CODE_REQUEST, InsertCodeRequestHandler::class)
put(DevChatActions.REPLACE_FILE_CONTENT_REQUEST, ReplaceFileContentHandler::class)
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/ai/devchat/devchat/DevChatActions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ object DevChatActions {
const val LOAD_CONVERSATIONS_RESPONSE = "loadConversations/response"
const val LOAD_HISTORY_MESSAGES_REQUEST = "loadHistoryMessages/request"
const val LOAD_HISTORY_MESSAGES_RESPONSE = "loadHistoryMessages/response"
const val LIST_CONVERSATIONS_RESPONSE = "listConversations/response"
const val LIST_TOPICS_REQUEST = "listTopics/request"
const val LIST_TOPICS_RESPONSE = "listTopics/response"
const val INSERT_CODE_REQUEST = "insertCode/request"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ai.devchat.devchat.handler

import ai.devchat.common.Log
import ai.devchat.devchat.ActionHandler
import ai.devchat.devchat.DevChatActionHandler
import ai.devchat.devchat.DevChatActions
import ai.devchat.idea.setting.DevChatSettingsState
import ai.devchat.idea.storage.ActiveConversation
import com.alibaba.fastjson.JSONObject

class LoadHistoryMessagesRequestHandler(private val handler: DevChatActionHandler) : ActionHandler {
private var metadata: JSONObject? = null
private var payload: JSONObject? = null

private fun action(res: JSONObject) {
val pageSize = DevChatSettingsState.instance.maxLogCount
val pageIndex = metadata!!.getInteger("pageIndex") ?: 1
res["messages"] = ActiveConversation.getMessages(pageIndex, pageSize)
}

override fun executeAction() {
handler.handle(
DevChatActions.LOAD_HISTORY_MESSAGES_RESPONSE,
metadata!!.getString("callback"),
::action
)
}

override fun setMetadata(metadata: JSONObject) {
this.metadata = metadata
}

override fun setPayload(payload: JSONObject) {
this.payload = payload
}
}

0 comments on commit c403019

Please sign in to comment.