Commit 9206d6d4 authored by Steven杜宇's avatar Steven杜宇

// AI

parent 7582e78c
...@@ -20,7 +20,7 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -20,7 +20,7 @@ class YHAIMainChatViewController: YHBaseViewController {
var isUserScrolling: Bool = false var isUserScrolling: Bool = false
var lastUserScrollTime: CFTimeInterval = 0.0 var lastUserScrollTime: CFTimeInterval = 0.0
let minimumScrollInterval: CFTimeInterval = 3.0 let minimumScrollInterval: CFTimeInterval = 2.0
let manager = YHAIRequestManager() let manager = YHAIRequestManager()
let viewModel = YHAIViewModel() let viewModel = YHAIViewModel()
...@@ -111,10 +111,10 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -111,10 +111,10 @@ class YHAIMainChatViewController: YHBaseViewController {
self.bottomInputView.showKeyBoard(false) self.bottomInputView.showKeyBoard(false)
} }
func reloadAndScrollToBottom() { func reloadAndScrollToBottom(_ forceScrollToBottom: Bool = false) {
self.tableView.reloadData() self.tableView.reloadData()
if !canTriggerProgrammaticScroll() { if !forceScrollToBottom && !canTriggerProgrammaticScroll() {
return return
} }
...@@ -133,7 +133,7 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -133,7 +133,7 @@ class YHAIMainChatViewController: YHBaseViewController {
} }
} }
func sendMessage(_ text: String) { func sendMessage(_ text: String, _ forceScrollToBottom: Bool = false) {
self.manager.getMainChatConversationId { self.manager.getMainChatConversationId {
sesseionId in sesseionId in
self.conversationId = sesseionId self.conversationId = sesseionId
...@@ -141,7 +141,7 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -141,7 +141,7 @@ class YHAIMainChatViewController: YHBaseViewController {
let question = YHAIChatMessage.createQuestionMessage(text) let question = YHAIChatMessage.createQuestionMessage(text)
self.messages.append(question) self.messages.append(question)
self.messages.append(self.thinkingMessage) self.messages.append(self.thinkingMessage)
self.reloadAndScrollToBottom() self.reloadAndScrollToBottom(forceScrollToBottom)
self.bottomInputView.status = .loading self.bottomInputView.status = .loading
self.chatConfig.disableHandleMessage = false self.chatConfig.disableHandleMessage = false
self.manager.requestAI(botId: self.robotId, conversationId: self.conversationId, question:text) { self.manager.requestAI(botId: self.robotId, conversationId: self.conversationId, question:text) {
...@@ -152,7 +152,7 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -152,7 +152,7 @@ class YHAIMainChatViewController: YHBaseViewController {
print("RESPONSE-DONE") print("RESPONSE-DONE")
self.bottomInputView.status = self.bottomInputView.textView.text.isEmpty ? .disableSend : .enableSend self.bottomInputView.status = self.bottomInputView.textView.text.isEmpty ? .disableSend : .enableSend
} }
self.reloadAndScrollToBottom() self.reloadAndScrollToBottom(forceScrollToBottom)
} }
} }
} }
...@@ -383,9 +383,9 @@ extension YHAIMainChatViewController: UITableViewDelegate, UITableViewDataSource ...@@ -383,9 +383,9 @@ extension YHAIMainChatViewController: UITableViewDelegate, UITableViewDataSource
} }
// 检查是否可以执行代码触发的滚动 // 检查是否可以执行代码触发的滚动
private func canTriggerProgrammaticScroll() -> Bool { func canTriggerProgrammaticScroll() -> Bool {
let currentTime = CACurrentMediaTime() let currentTime = CACurrentMediaTime()
return !self.tableView.isDragging && (currentTime - lastUserScrollTime) >= minimumScrollInterval return (currentTime - lastUserScrollTime) >= minimumScrollInterval
} }
} }
......
...@@ -95,11 +95,11 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -95,11 +95,11 @@ class YHAIRobotChatViewController: YHBaseViewController {
if self.isNeedStopResonse() { if self.isNeedStopResonse() {
self.stopAutoResponse { success in self.stopAutoResponse { success in
if success { if success {
self.sendMessage(text) self.sendMessage(text, true)
} }
} }
} else { } else {
self.sendMessage(text) self.sendMessage(text, true)
} }
} }
view.selectBannerItemBlock = { view.selectBannerItemBlock = {
...@@ -116,11 +116,11 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -116,11 +116,11 @@ class YHAIRobotChatViewController: YHBaseViewController {
if self.isNeedStopResonse() { if self.isNeedStopResonse() {
self.stopAutoResponse { success in self.stopAutoResponse { success in
if success { if success {
self.sendMessage(text) self.sendMessage(text, true)
} }
} }
} else { } else {
self.sendMessage(text) self.sendMessage(text, true)
} }
} }
return view return view
...@@ -186,10 +186,10 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -186,10 +186,10 @@ class YHAIRobotChatViewController: YHBaseViewController {
self.navigationController?.popViewController(animated: true) self.navigationController?.popViewController(animated: true)
} }
func reloadAndScrollToBottom() { func reloadAndScrollToBottom(_ forceScrollToBottom: Bool = false) {
self.tableView.reloadData() self.tableView.reloadData()
if !canTriggerProgrammaticScroll() { if !forceScrollToBottom && !canTriggerProgrammaticScroll() {
return return
} }
...@@ -208,7 +208,7 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -208,7 +208,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
} }
} }
func sendMessage(_ text: String) { func sendMessage(_ text: String, _ forceScrollToBottom: Bool = false) {
self.chatConfig.removeThinkingMessageFromChatList(&messages) self.chatConfig.removeThinkingMessageFromChatList(&messages)
let question = YHAIChatMessage.createQuestionMessage(text) let question = YHAIChatMessage.createQuestionMessage(text)
...@@ -216,7 +216,7 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -216,7 +216,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
messages.append(thinkingMessage) messages.append(thinkingMessage)
self.bottomInputView.status = .loading self.bottomInputView.status = .loading
self.chatConfig.disableHandleMessage = false self.chatConfig.disableHandleMessage = false
self.reloadAndScrollToBottom() self.reloadAndScrollToBottom(forceScrollToBottom)
self.manager.requestAI(botId: self.robotId, conversationId: self.conversationId, question:text) { self.manager.requestAI(botId: self.robotId, conversationId: self.conversationId, question:text) {
[weak self] res, done in [weak self] res, done in
guard let self = self else { return } guard let self = self else { return }
...@@ -225,7 +225,7 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -225,7 +225,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
print("RESPONSE-DONE") print("RESPONSE-DONE")
self.bottomInputView.status = self.bottomInputView.textView.text.isEmpty ? .disableSend : .enableSend self.bottomInputView.status = self.bottomInputView.textView.text.isEmpty ? .disableSend : .enableSend
} }
self.reloadAndScrollToBottom() self.reloadAndScrollToBottom(forceScrollToBottom)
} }
} }
...@@ -264,7 +264,7 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -264,7 +264,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
} }
} }
self.reloadAndScrollToBottom() self.reloadAndScrollToBottom(true)
} }
func uploadEvaluationMessage(_ msg: YHAIChatMessage, callback:((Bool)->())? = nil) { func uploadEvaluationMessage(_ msg: YHAIChatMessage, callback:((Bool)->())? = nil) {
...@@ -402,11 +402,11 @@ extension YHAIRobotChatViewController: UITableViewDelegate, UITableViewDataSourc ...@@ -402,11 +402,11 @@ extension YHAIRobotChatViewController: UITableViewDelegate, UITableViewDataSourc
if self.isNeedStopResonse() { if self.isNeedStopResonse() {
self.stopAutoResponse { success in self.stopAutoResponse { success in
if success { if success {
self.sendMessage(text) self.sendMessage(text, true)
} }
} }
} else { } else {
self.sendMessage(text) self.sendMessage(text, true)
} }
} }
return cell return cell
...@@ -522,9 +522,9 @@ extension YHAIRobotChatViewController: UITableViewDelegate, UITableViewDataSourc ...@@ -522,9 +522,9 @@ extension YHAIRobotChatViewController: UITableViewDelegate, UITableViewDataSourc
} }
// 检查是否可以执行代码触发的滚动 // 检查是否可以执行代码触发的滚动
private func canTriggerProgrammaticScroll() -> Bool { func canTriggerProgrammaticScroll() -> Bool {
let currentTime = CACurrentMediaTime() let currentTime = CACurrentMediaTime()
return !self.tableView.isDragging && (currentTime - lastUserScrollTime) >= minimumScrollInterval return (currentTime - lastUserScrollTime) >= minimumScrollInterval
} }
} }
......
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