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

// AI

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