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

// AI

parent 8dc51d36
...@@ -37,9 +37,6 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -37,9 +37,6 @@ class YHAIMainChatViewController: YHBaseViewController {
tableView.delegate = self tableView.delegate = self
tableView.dataSource = self tableView.dataSource = self
YHAIChatConfiguration.defaultConfig.registerMessageGroupCells(tableView) YHAIChatConfiguration.defaultConfig.registerMessageGroupCells(tableView)
// tableView.es.addYHPullToRefresh {
// self.getHistoryMessages(false)
// }
return tableView return tableView
}() }()
...@@ -142,8 +139,9 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -142,8 +139,9 @@ class YHAIMainChatViewController: YHBaseViewController {
} }
} }
func getHistoryMessages(_ isLoading: Bool) { // isPull 是否是下拉组件触发
if isLoading { func getHistoryMessages(_ isPull: Bool) {
if !isPull {
YHHUD.show(.progress(message: "加载中...")) YHHUD.show(.progress(message: "加载中..."))
} }
viewModel.getHistoryChatMessages(botId: robotId, conversationId: conversationId, messageId: historyLastMessageId) { viewModel.getHistoryChatMessages(botId: robotId, conversationId: conversationId, messageId: historyLastMessageId) {
...@@ -152,9 +150,21 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -152,9 +150,21 @@ class YHAIMainChatViewController: YHBaseViewController {
guard let self = self else { return } guard let self = self else { return }
self.historyLastMessageId = self.viewModel.lastHistroyMsgId self.historyLastMessageId = self.viewModel.lastHistroyMsgId
self.tableView.es.stopPullToRefresh() self.tableView.es.stopPullToRefresh()
let results = self.viewModel.historyMessages.map { let results = self.viewModel.historyMessages.map {
return $0.convertToChatMessage() 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) messages.insert(contentsOf: results, at: 0)
self.tableView.reloadData() self.tableView.reloadData()
} }
......
...@@ -35,9 +35,6 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -35,9 +35,6 @@ class YHAIRobotChatViewController: YHBaseViewController {
tableView.delegate = self tableView.delegate = self
tableView.dataSource = self tableView.dataSource = self
YHAIChatConfiguration.defaultConfig.registerMessageGroupCells(tableView) YHAIChatConfiguration.defaultConfig.registerMessageGroupCells(tableView)
// tableView.es.addYHPullToRefresh {
// self.getHistoryMessages(false)
// }
return tableView return tableView
}() }()
...@@ -123,7 +120,7 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -123,7 +120,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
make.left.right.bottom.equalToSuperview() make.left.right.bottom.equalToSuperview()
} }
getHistoryMessages(true) getHistoryMessages(false)
} }
func scrollToBottom() { func scrollToBottom() {
...@@ -155,8 +152,9 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -155,8 +152,9 @@ class YHAIRobotChatViewController: YHBaseViewController {
} }
} }
func getHistoryMessages(_ isLoading: Bool) { // isPull 是否是下拉组件触发
if isLoading { func getHistoryMessages(_ isPull: Bool) {
if !isPull {
YHHUD.show(.progress(message: "加载中...")) YHHUD.show(.progress(message: "加载中..."))
} }
viewModel.getHistoryChatMessages(botId: robotId, conversationId: conversationId, messageId: historyLastMessageId) { viewModel.getHistoryChatMessages(botId: robotId, conversationId: conversationId, messageId: historyLastMessageId) {
...@@ -165,14 +163,27 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -165,14 +163,27 @@ class YHAIRobotChatViewController: YHBaseViewController {
guard let self = self else { return } guard let self = self else { return }
self.historyLastMessageId = self.viewModel.lastHistroyMsgId self.historyLastMessageId = self.viewModel.lastHistroyMsgId
self.tableView.es.stopPullToRefresh() self.tableView.es.stopPullToRefresh()
let results = self.viewModel.historyMessages.map { let results = self.viewModel.historyMessages.map {
return $0.convertToChatMessage() 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) messages.insert(contentsOf: results, at: 0)
self.tableView.reloadData() self.tableView.reloadData()
} }
} }
func uploadEvaluationMessage(_ msg: YHAIChatMessage, callback:((Bool)->())? = nil) { func uploadEvaluationMessage(_ msg: YHAIChatMessage, callback:((Bool)->())? = nil) {
viewModel.createMessage(conversationId: conversationId, role: "assistant", msg: msg) { viewModel.createMessage(conversationId: conversationId, role: "assistant", msg: msg) {
[weak self] success, error in [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