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

// AI

parent 2aa2e989
......@@ -188,6 +188,19 @@ class YHAIMainChatViewController: YHBaseViewController {
callback?(success)
}
}
@objc func didCleanButtonClicked() {
self.manager.clearGlobalConverastionId()
self.viewModel.requestConversationId { sessionId in
if !sessionId.isEmpty {
self.conversationId = sessionId
self.manager.saveGlobalConverastionId(sessionId)
self.messages.removeAll()
self.tableView.reloadData()
YHHUD.flash(message: "清除成功")
}
}
}
}
extension YHAIMainChatViewController: UITableViewDelegate, UITableViewDataSource {
......
......@@ -265,25 +265,50 @@ extension YHAIRequestManager {
return ""
}
func clearGlobalConverastionId() {
let userId = YHLoginManager.shared.userModel?.id ?? ""
let key = Self.sessionKey + userId
UserDefaults.standard.set(nil, forKey: key)
UserDefaults.standard.synchronize()
}
func getSubRobotChatConversationId(robotId: String, completion:((String)->())?) {
let localConversationId = getLobalSubRobotConversationId(robotId: robotId)
if !localConversationId.isEmpty {
completion?(localConversationId)
return
}
self.viewModel.requestConversationId { sessionId in
self.saveLobalSubRobotConversationId(sessionId, robotId: robotId)
completion?(sessionId)
}
}
func getLobalSubRobotConversationId(robotId: String) -> String {
let userId = YHLoginManager.shared.userModel?.id ?? ""
let key = Self.subrobotConversationConfigKey + userId
if let dict = UserDefaults.standard.dictionary(forKey: key) {
if let conversationId = dict["\(robotId)"] as? String, !conversationId.isEmpty {
return conversationId
}
}
return ""
}
func saveLobalSubRobotConversationId(_ converId: String, robotId: String) {
let userId = YHLoginManager.shared.userModel?.id ?? ""
let key = Self.subrobotConversationConfigKey + userId
var dict:[String : Any] = [:]
if let config = UserDefaults.standard.dictionary(forKey: key) {
dict = config
}
if let conversationId = dict["\(robotId)"] as? String, !conversationId.isEmpty {
completion?(conversationId)
return
}
self.viewModel.requestConversationId { sessionId in
dict["\(robotId)"] = sessionId
UserDefaults.standard.set(dict, forKey: key)
UserDefaults.standard.synchronize()
completion?(sessionId)
}
dict["\(robotId)"] = converId
UserDefaults.standard.set(dict, forKey: key)
UserDefaults.standard.synchronize()
}
func clearLobalSubRobotConversationIdForRobotId(_ robotId: String) {
saveLobalSubRobotConversationId("", robotId: robotId)
}
}
......@@ -206,10 +206,11 @@ class YHAIRobotChatViewController: YHBaseViewController {
@objc func didCleanButtonClicked() {
self.manager.clearLobalSubRobotConversationIdForRobotId(robotId)
self.viewModel.requestConversationId { sessionId in
if !sessionId.isEmpty {
self.conversationId = sessionId
self.manager.saveGlobalConverastionId(sessionId)
self.manager.saveLobalSubRobotConversationId(sessionId, robotId: self.robotId)
self.messages.removeAll()
self.tableView.reloadData()
YHHUD.flash(message: "清除成功")
......
......@@ -67,6 +67,15 @@ class YHAITabViewController: YHBaseViewController {
return btn
}()
lazy var cleanBtn: UIButton = {
let btn = UIButton()
btn.setImage(UIImage(named: "msg_clean"), for: .normal)
btn.YH_clickEdgeInsets = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
btn.addTarget(self, action: #selector(didCleanButtonClicked), for: .touchUpInside)
btn.isHidden = true
return btn
}()
lazy var listVC: YHAIServiceListViewController = {
let vc = YHAIServiceListViewController()
return vc
......@@ -124,7 +133,7 @@ class YHAITabViewController: YHBaseViewController {
segmentedView.listContainer = listContainerView
view.addSubview(listContainerView)
view.addSubview(cleanBtn)
//分类Title
segmentedView.dataSource = segmentedDataSource
......@@ -168,6 +177,12 @@ class YHAITabViewController: YHBaseViewController {
make.top.equalTo(k_Height_safeAreaInsetsTop() + segmentHeight)
make.bottom.equalTo(0)
}
cleanBtn.snp.makeConstraints { make in
make.width.height.equalTo(24)
make.centerY.equalTo(segmentedView)
make.right.equalToSuperview().offset(-20)
}
}
func requestList() {
......@@ -191,6 +206,10 @@ class YHAITabViewController: YHBaseViewController {
jumpToItemIndex(itemIndex: 1)
mainChatVC.bottomInputView.showKeyBoard()
}
@objc func didCleanButtonClicked() {
self.mainChatVC.didCleanButtonClicked()
}
}
extension YHAITabViewController: JXSegmentedViewDelegate {
......@@ -200,10 +219,12 @@ extension YHAITabViewController: JXSegmentedViewDelegate {
if segmentedView.selectedIndex == 1 { // AI对话
bgImgView.isHidden = false
headerImgView.isHidden = true
cleanBtn.isHidden = false
} else { // 港小宝
bgImgView.isHidden = true
headerImgView.isHidden = false
cleanBtn.isHidden = true
}
}
}
......
......@@ -43,10 +43,7 @@ class YHAIChatMessage: CustomStringConvertible {
var body = YHAIMessageBody()
func isFinishd() -> Bool {
if event.isEmpty {
return true
}
if event == "conversation.message.completed" {
if event.contains("conversation.message.completed") {
return true
}
return false
......@@ -178,7 +175,7 @@ class YHAIChatMessage: CustomStringConvertible {
}
var description: String {
return "uudi:\(messageId)\n id: \(id)\n event: \(event)\n data:\(data)\n \n"
return "uudi:\(messageId)\n id:\(id)\n event:\(event)\n data:\(data)\n \n"
}
}
......
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