Commit f9143eac authored by Steven杜宇's avatar Steven杜宇

// AI

parent 77223e6f
...@@ -97,7 +97,7 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -97,7 +97,7 @@ class YHAIMainChatViewController: YHBaseViewController {
sesseionId in sesseionId in
YHHUD.hide() YHHUD.hide()
self.conversationId = sesseionId self.conversationId = sesseionId
self.getHistoryMessages(false) self.getHistoryMessages()
} }
} }
...@@ -111,7 +111,7 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -111,7 +111,7 @@ class YHAIMainChatViewController: YHBaseViewController {
self.bottomInputView.showKeyBoard(false) self.bottomInputView.showKeyBoard(false)
} }
func reloadAndScrollToBottom(_ forceScrollToBottom: Bool = false) { func reloadAndScrollToBottom(_ forceScrollToBottom: Bool = false, _ isNeedAccurate: Bool = false) {
self.tableView.reloadData() self.tableView.reloadData()
if !forceScrollToBottom && !canTriggerProgrammaticScroll() { if !forceScrollToBottom && !canTriggerProgrammaticScroll() {
...@@ -119,8 +119,12 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -119,8 +119,12 @@ class YHAIMainChatViewController: YHBaseViewController {
} }
DispatchQueue.main.asyncAfter(deadline: .now()+0.5) { DispatchQueue.main.asyncAfter(deadline: .now()+0.5) {
// self.tableView.setContentOffset(.zero, animated: true)
// self.tableView.setContentOffset(CGPointMake(0, 90000), animated: true) if isNeedAccurate {
self.tableView.setContentOffset(.zero, animated: true)
self.tableView.setContentOffset(CGPointMake(0, 90000), animated: true)
}
// 使用 performBatchUpdates 来确保所有布局更新完成后再滚动 // 使用 performBatchUpdates 来确保所有布局更新完成后再滚动
self.tableView.performBatchUpdates(nil) { _ in self.tableView.performBatchUpdates(nil) { _ in
...@@ -158,10 +162,8 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -158,10 +162,8 @@ class YHAIMainChatViewController: YHBaseViewController {
} }
// isPull 是否是下拉组件触发 // isPull 是否是下拉组件触发
func getHistoryMessages(_ isPull: Bool) { func getHistoryMessages() {
if !isPull { YHHUD.show(.progress(message: "加载历史消息中..."))
YHHUD.show(.progress(message: "加载中..."))
}
viewModel.getHistoryChatMessages(botId: robotId, conversationId: conversationId, messageId: "") { viewModel.getHistoryChatMessages(botId: robotId, conversationId: conversationId, messageId: "") {
[weak self] success, error in [weak self] success, error in
YHHUD.hide() YHHUD.hide()
...@@ -180,7 +182,7 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -180,7 +182,7 @@ class YHAIMainChatViewController: YHBaseViewController {
return !uuids.contains($0.messageId) return !uuids.contains($0.messageId)
} }
messages.insert(contentsOf: results, at: 0) messages.insert(contentsOf: results, at: 0)
self.reloadAndScrollToBottom() self.reloadAndScrollToBottom(true, true)
} }
} }
......
...@@ -186,7 +186,7 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -186,7 +186,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
self.navigationController?.popViewController(animated: true) self.navigationController?.popViewController(animated: true)
} }
func reloadAndScrollToBottom(_ forceScrollToBottom: Bool = false) { func reloadAndScrollToBottom(_ forceScrollToBottom: Bool = false, _ isNeedAccurate: Bool = false) {
self.tableView.reloadData() self.tableView.reloadData()
if !forceScrollToBottom && !canTriggerProgrammaticScroll() { if !forceScrollToBottom && !canTriggerProgrammaticScroll() {
...@@ -194,8 +194,12 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -194,8 +194,12 @@ class YHAIRobotChatViewController: YHBaseViewController {
} }
DispatchQueue.main.asyncAfter(deadline: .now()+0.5) { DispatchQueue.main.asyncAfter(deadline: .now()+0.5) {
// self.tableView.setContentOffset(.zero, animated: true)
// self.tableView.setContentOffset(CGPointMake(0, 90000), animated: true) if isNeedAccurate {
self.tableView.setContentOffset(.zero, animated: true)
self.tableView.setContentOffset(CGPointMake(0, 90000), animated: true)
}
// 使用 performBatchUpdates 来确保所有布局更新完成后再滚动 // 使用 performBatchUpdates 来确保所有布局更新完成后再滚动
self.tableView.performBatchUpdates(nil) { _ in self.tableView.performBatchUpdates(nil) { _ in
...@@ -231,10 +235,10 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -231,10 +235,10 @@ class YHAIRobotChatViewController: YHBaseViewController {
func getHistoryMessages() { func getHistoryMessages() {
// YHHUD.show(.progress(message: "加载中...")) YHHUD.show(.progress(message: "加载历史消息中..."))
viewModel.getHistoryChatMessages(botId: robotId, conversationId: conversationId, messageId: "") { viewModel.getHistoryChatMessages(botId: robotId, conversationId: conversationId, messageId: "") {
[weak self] success, error in [weak self] success, error in
// YHHUD.hide() YHHUD.hide()
guard let self = self else { return } guard let self = self else { return }
var results = self.viewModel.historyMessages.map { var results = self.viewModel.historyMessages.map {
...@@ -249,7 +253,7 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -249,7 +253,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
return !uuids.contains($0.messageId) return !uuids.contains($0.messageId)
} }
messages.insert(contentsOf: results, at: 0) messages.insert(contentsOf: results, at: 0)
self.tableView.reloadData() reloadAndScrollToBottom(true, true)
autoResponseLocalTextMessage() autoResponseLocalTextMessage()
} }
...@@ -374,7 +378,6 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -374,7 +378,6 @@ class YHAIRobotChatViewController: YHBaseViewController {
func isNeedStopResonse() -> Bool { func isNeedStopResonse() -> Bool {
return self.bottomInputView.status == .loading return self.bottomInputView.status == .loading
} }
} }
extension YHAIRobotChatViewController: UITableViewDelegate, UITableViewDataSource { extension YHAIRobotChatViewController: UITableViewDelegate, UITableViewDataSource {
......
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