Commit 1beeb09e authored by Steven杜宇's avatar Steven杜宇

// AI

parent 8dc51d36
......@@ -37,9 +37,6 @@ class YHAIMainChatViewController: YHBaseViewController {
tableView.delegate = self
tableView.dataSource = self
YHAIChatConfiguration.defaultConfig.registerMessageGroupCells(tableView)
// tableView.es.addYHPullToRefresh {
// self.getHistoryMessages(false)
// }
return tableView
}()
......@@ -142,8 +139,9 @@ class YHAIMainChatViewController: YHBaseViewController {
}
}
func getHistoryMessages(_ isLoading: Bool) {
if isLoading {
// isPull 是否是下拉组件触发
func getHistoryMessages(_ isPull: Bool) {
if !isPull {
YHHUD.show(.progress(message: "加载中..."))
}
viewModel.getHistoryChatMessages(botId: robotId, conversationId: conversationId, messageId: historyLastMessageId) {
......@@ -152,9 +150,21 @@ class YHAIMainChatViewController: YHBaseViewController {
guard let self = self else { return }
self.historyLastMessageId = self.viewModel.lastHistroyMsgId
self.tableView.es.stopPullToRefresh()
let results = self.viewModel.historyMessages.map {
return $0.convertToChatMessage()
}
if !isPull {
if results.count <= 0 { // 无聊天记录时隐藏下拉组件
tableView.header = nil
} else {
tableView.es.addYHPullToRefresh {
self.getHistoryMessages(true)
}
}
}
messages.insert(contentsOf: results, at: 0)
self.tableView.reloadData()
}
......
......@@ -35,9 +35,6 @@ class YHAIRobotChatViewController: YHBaseViewController {
tableView.delegate = self
tableView.dataSource = self
YHAIChatConfiguration.defaultConfig.registerMessageGroupCells(tableView)
// tableView.es.addYHPullToRefresh {
// self.getHistoryMessages(false)
// }
return tableView
}()
......@@ -123,7 +120,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
make.left.right.bottom.equalToSuperview()
}
getHistoryMessages(true)
getHistoryMessages(false)
}
func scrollToBottom() {
......@@ -155,8 +152,9 @@ class YHAIRobotChatViewController: YHBaseViewController {
}
}
func getHistoryMessages(_ isLoading: Bool) {
if isLoading {
// isPull 是否是下拉组件触发
func getHistoryMessages(_ isPull: Bool) {
if !isPull {
YHHUD.show(.progress(message: "加载中..."))
}
viewModel.getHistoryChatMessages(botId: robotId, conversationId: conversationId, messageId: historyLastMessageId) {
......@@ -165,14 +163,27 @@ class YHAIRobotChatViewController: YHBaseViewController {
guard let self = self else { return }
self.historyLastMessageId = self.viewModel.lastHistroyMsgId
self.tableView.es.stopPullToRefresh()
let results = self.viewModel.historyMessages.map {
return $0.convertToChatMessage()
}
if !isPull {
if results.count <= 0 { // 无聊天记录时隐藏下拉组件
tableView.header = nil
} else {
tableView.es.addYHPullToRefresh {
self.getHistoryMessages(true)
}
}
}
messages.insert(contentsOf: results, at: 0)
self.tableView.reloadData()
}
}
func uploadEvaluationMessage(_ msg: YHAIChatMessage, callback:((Bool)->())? = nil) {
viewModel.createMessage(conversationId: conversationId, role: "assistant", msg: msg) {
[weak self] success, error in
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment