Commit 125dde55 authored by Steven杜宇's avatar Steven杜宇

// AI

parent b8f8d237
...@@ -577,7 +577,7 @@ ...@@ -577,7 +577,7 @@
04943BE82CF0A0B500BF2255 /* submit_page_scroll.gif in Resources */ = {isa = PBXBuildFile; fileRef = 04943BE72CF0A0B500BF2255 /* submit_page_scroll.gif */; }; 04943BE82CF0A0B500BF2255 /* submit_page_scroll.gif in Resources */ = {isa = PBXBuildFile; fileRef = 04943BE72CF0A0B500BF2255 /* submit_page_scroll.gif */; };
04943BEA2CF1B44100BF2255 /* YHAIMainChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04943BE92CF1B44100BF2255 /* YHAIMainChatViewController.swift */; }; 04943BEA2CF1B44100BF2255 /* YHAIMainChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04943BE92CF1B44100BF2255 /* YHAIMainChatViewController.swift */; };
04943BED2CF46B6600BF2255 /* YHAIRequestManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04943BEC2CF46B6600BF2255 /* YHAIRequestManager.swift */; }; 04943BED2CF46B6600BF2255 /* YHAIRequestManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04943BEC2CF46B6600BF2255 /* YHAIRequestManager.swift */; };
04943BF42CF4954800BF2255 /* YHAIMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04943BF32CF4954800BF2255 /* YHAIMessageCell.swift */; }; 04943BF42CF4954800BF2255 /* YHAITextMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04943BF32CF4954800BF2255 /* YHAITextMessageCell.swift */; };
04943BF62CF49E3E00BF2255 /* YHAITextInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04943BF52CF49E3E00BF2255 /* YHAITextInputView.swift */; }; 04943BF62CF49E3E00BF2255 /* YHAITextInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04943BF52CF49E3E00BF2255 /* YHAITextInputView.swift */; };
049537852BA9B28500AF7E59 /* YHCertificateTemplateCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049537842BA9B28500AF7E59 /* YHCertificateTemplateCell.swift */; }; 049537852BA9B28500AF7E59 /* YHCertificateTemplateCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049537842BA9B28500AF7E59 /* YHCertificateTemplateCell.swift */; };
049663BA2BF6105C003C8295 /* YHRefreshHeaderAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049663B92BF6105C003C8295 /* YHRefreshHeaderAnimator.swift */; }; 049663BA2BF6105C003C8295 /* YHRefreshHeaderAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049663B92BF6105C003C8295 /* YHRefreshHeaderAnimator.swift */; };
...@@ -1643,7 +1643,7 @@ ...@@ -1643,7 +1643,7 @@
04943BE72CF0A0B500BF2255 /* submit_page_scroll.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = submit_page_scroll.gif; sourceTree = "<group>"; }; 04943BE72CF0A0B500BF2255 /* submit_page_scroll.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = submit_page_scroll.gif; sourceTree = "<group>"; };
04943BE92CF1B44100BF2255 /* YHAIMainChatViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAIMainChatViewController.swift; sourceTree = "<group>"; }; 04943BE92CF1B44100BF2255 /* YHAIMainChatViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAIMainChatViewController.swift; sourceTree = "<group>"; };
04943BEC2CF46B6600BF2255 /* YHAIRequestManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAIRequestManager.swift; sourceTree = "<group>"; }; 04943BEC2CF46B6600BF2255 /* YHAIRequestManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAIRequestManager.swift; sourceTree = "<group>"; };
04943BF32CF4954800BF2255 /* YHAIMessageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAIMessageCell.swift; sourceTree = "<group>"; }; 04943BF32CF4954800BF2255 /* YHAITextMessageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAITextMessageCell.swift; sourceTree = "<group>"; };
04943BF52CF49E3E00BF2255 /* YHAITextInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAITextInputView.swift; sourceTree = "<group>"; }; 04943BF52CF49E3E00BF2255 /* YHAITextInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAITextInputView.swift; sourceTree = "<group>"; };
049537842BA9B28500AF7E59 /* YHCertificateTemplateCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHCertificateTemplateCell.swift; sourceTree = "<group>"; }; 049537842BA9B28500AF7E59 /* YHCertificateTemplateCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHCertificateTemplateCell.swift; sourceTree = "<group>"; };
049663B92BF6105C003C8295 /* YHRefreshHeaderAnimator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHRefreshHeaderAnimator.swift; sourceTree = "<group>"; }; 049663B92BF6105C003C8295 /* YHRefreshHeaderAnimator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHRefreshHeaderAnimator.swift; sourceTree = "<group>"; };
...@@ -3995,7 +3995,7 @@ ...@@ -3995,7 +3995,7 @@
04943BF12CF4947F00BF2255 /* V */ = { 04943BF12CF4947F00BF2255 /* V */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
04943BF32CF4954800BF2255 /* YHAIMessageCell.swift */, 04943BF32CF4954800BF2255 /* YHAITextMessageCell.swift */,
04BE392B2CF8917100BD31DB /* YHAIThinkingMessageCell.swift */, 04BE392B2CF8917100BD31DB /* YHAIThinkingMessageCell.swift */,
04BE392D2CF964A200BD31DB /* YHProductListMessageCell.swift */, 04BE392D2CF964A200BD31DB /* YHProductListMessageCell.swift */,
04BE39332CF9AFAE00BD31DB /* YHFixProductMessageCell.swift */, 04BE39332CF9AFAE00BD31DB /* YHFixProductMessageCell.swift */,
...@@ -6150,7 +6150,7 @@ ...@@ -6150,7 +6150,7 @@
04CE1AD82C2AD91F001CB80A /* YHActivityListViewController.swift in Sources */, 04CE1AD82C2AD91F001CB80A /* YHActivityListViewController.swift in Sources */,
A5ACE94E2B4564F7002C94D2 /* AlignedCollectionViewFlowLayout.swift in Sources */, A5ACE94E2B4564F7002C94D2 /* AlignedCollectionViewFlowLayout.swift in Sources */,
A567E5B32BD7643D00D5D5A0 /* YHServiceOrderAlertView.swift in Sources */, A567E5B32BD7643D00D5D5A0 /* YHServiceOrderAlertView.swift in Sources */,
04943BF42CF4954800BF2255 /* YHAIMessageCell.swift in Sources */, 04943BF42CF4954800BF2255 /* YHAITextMessageCell.swift in Sources */,
A592FE932BA6CFFC0062FACA /* YHCertificateEntryBottomView.swift in Sources */, A592FE932BA6CFFC0062FACA /* YHCertificateEntryBottomView.swift in Sources */,
A5ACE93B2B4564F7002C94D2 /* UIFont+Extension.swift in Sources */, A5ACE93B2B4564F7002C94D2 /* UIFont+Extension.swift in Sources */,
047F3DD92CE601D1001B2A6D /* YHEducationCertificateConfirmCell.swift in Sources */, 047F3DD92CE601D1001B2A6D /* YHEducationCertificateConfirmCell.swift in Sources */,
......
...@@ -16,19 +16,19 @@ class YHAIChatConfiguration { ...@@ -16,19 +16,19 @@ class YHAIChatConfiguration {
func registerMessageGroupCells(_ tableView: UITableView) { func registerMessageGroupCells(_ tableView: UITableView) {
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "UITableViewCell") tableView.register(UITableViewCell.self, forCellReuseIdentifier: "UITableViewCell")
tableView.register(YHAIMessageCell.self, forCellReuseIdentifier: YHAIMessageCell.cellReuseIdentifier) tableView.register(YHAITextMessageCell.self, forCellReuseIdentifier: YHAITextMessageCell.cellReuseIdentifier)
tableView.register(YHAIThinkingMessageCell.self, forCellReuseIdentifier: YHAIThinkingMessageCell.cellReuseIdentifier) tableView.register(YHAIThinkingMessageCell.self, forCellReuseIdentifier: YHAIThinkingMessageCell.cellReuseIdentifier)
tableView.register(YHProductListMessageCell.self, forCellReuseIdentifier: YHProductListMessageCell.cellReuseIdentifier) tableView.register(YHProductListMessageCell.self, forCellReuseIdentifier: YHProductListMessageCell.cellReuseIdentifier)
tableView.register(YHFixProductListMessageCell.self, forCellReuseIdentifier: YHFixProductListMessageCell.cellReuseIdentifier) tableView.register(YHFixProductListMessageCell.self, forCellReuseIdentifier: YHFixProductListMessageCell.cellReuseIdentifier)
tableView.register(YHCardMessageCell.self, forCellReuseIdentifier: YHCardMessageCell.cellReuseIdentifier) tableView.register(YHCardMessageCell.self, forCellReuseIdentifier: YHCardMessageCell.cellReuseIdentifier)
} }
func getMessageCell(_ msg: YHAIMessage, _ tableView: UITableView, indexPath: IndexPath) -> UITableViewCell { func getMessageCell(_ msg: YHAIChatMessage, _ tableView: UITableView, indexPath: IndexPath) -> UITableViewCell {
let msgType = msg.getType() let msgType = msg.getType()
if msgType == .text { if msg.isTextMessage() {
let cell = tableView.dequeueReusableCell(withIdentifier: YHAIMessageCell.cellReuseIdentifier, for: indexPath) as! YHAIMessageCell let cell = tableView.dequeueReusableCell(withIdentifier: YHAITextMessageCell.cellReuseIdentifier, for: indexPath) as! YHAITextMessageCell
cell.message = msg cell.message = msg
return cell return cell
...@@ -53,13 +53,19 @@ class YHAIChatConfiguration { ...@@ -53,13 +53,19 @@ class YHAIChatConfiguration {
} else if msgType == .card { } else if msgType == .card {
let cell = tableView.dequeueReusableCell(withIdentifier: YHCardMessageCell.cellReuseIdentifier, for: indexPath) as! YHCardMessageCell let cell = tableView.dequeueReusableCell(withIdentifier: YHCardMessageCell.cellReuseIdentifier, for: indexPath) as! YHCardMessageCell
return cell return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: YHAITextMessageCell.cellReuseIdentifier, for: indexPath) as! YHAITextMessageCell
msg.body.contentText = "无法识别该消息,请升级APP版本"
cell.message = msg
return cell
} }
let defaultCell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath) let defaultCell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath)
return defaultCell return defaultCell
} }
func handleReceiveMessage(_ res: YHAIMessage?, _ done: Bool, _ messages: inout [YHAIMessage]) { func handleReceiveMessage(_ res: YHAIChatMessage?, _ done: Bool, _ messages: inout [YHAIChatMessage]) {
if disableHandleMessage { if disableHandleMessage {
for msg in messages { for msg in messages {
...@@ -75,7 +81,7 @@ class YHAIChatConfiguration { ...@@ -75,7 +81,7 @@ class YHAIChatConfiguration {
for msg in messages { for msg in messages {
if msg.uuid == res.uuid { if msg.uuid == res.uuid {
let msgType = msg.getType() let msgType = msg.getType()
if msgType == .text, res.getType() == .text { if msg.isNeedSpiceMessage(), res.isNeedSpiceMessage() {
// 多个文字需要拼接 // 多个文字需要拼接
find = true find = true
msg.body.contentText += res.body.contentText msg.body.contentText += res.body.contentText
...@@ -95,7 +101,7 @@ class YHAIChatConfiguration { ...@@ -95,7 +101,7 @@ class YHAIChatConfiguration {
} }
func removeThinkingMessageFromChatList( _ messages: inout [YHAIMessage]) { func removeThinkingMessageFromChatList( _ messages: inout [YHAIChatMessage]) {
var findIndex = -1 var findIndex = -1
for (index, msg) in messages.enumerated() { for (index, msg) in messages.enumerated() {
if msg.getType() == .thinking { if msg.getType() == .thinking {
......
...@@ -14,7 +14,7 @@ import JXSegmentedView ...@@ -14,7 +14,7 @@ import JXSegmentedView
class YHAIMainChatViewController: YHBaseViewController { class YHAIMainChatViewController: YHBaseViewController {
var robotId: String = "" var robotId: String = ""
var messages:[YHAIMessage] = [] var messages:[YHAIChatMessage] = []
let manager = YHAIRequestManager() let manager = YHAIRequestManager()
var conversationId: String = "" var conversationId: String = ""
...@@ -42,19 +42,17 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -42,19 +42,17 @@ class YHAIMainChatViewController: YHBaseViewController {
v.sendBlock = { v.sendBlock = {
[weak self] text in [weak self] text in
guard let self = self else { return } guard let self = self else { return }
YHAIChatConfiguration.defaultConfig.disableHandleMessage = false self.manager.getMainChatConversationId {
YHAIChatConfiguration.defaultConfig.removeThinkingMessageFromChatList(&messages)
let question = YHAIMessage.createQuestionMessage(text)
messages.append(question)
messages.append(thinkingMessage)
self.scrollToBottom()
manager.getMainChatConversationId {
sesseionId in sesseionId in
self.conversationId = sesseionId self.conversationId = sesseionId
YHAIChatConfiguration.defaultConfig.removeThinkingMessageFromChatList(&self.messages)
let question = YHAIChatMessage.createQuestionMessage(text)
self.messages.append(question)
self.messages.append(self.thinkingMessage)
self.scrollToBottom()
self.bottomInputView.status = .loading self.bottomInputView.status = .loading
YHAIChatConfiguration.defaultConfig.disableHandleMessage = true YHAIChatConfiguration.defaultConfig.disableHandleMessage = false
self.manager.requestAI(botId: self.robotId, conversationId: sesseionId, 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 }
YHAIChatConfiguration.defaultConfig.handleReceiveMessage(res, done, &messages) YHAIChatConfiguration.defaultConfig.handleReceiveMessage(res, done, &messages)
...@@ -64,7 +62,6 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -64,7 +62,6 @@ class YHAIMainChatViewController: YHBaseViewController {
self.scrollToBottom() self.scrollToBottom()
} }
} }
} }
v.stopSendBlock = { v.stopSendBlock = {
[weak self] in [weak self] in
...@@ -82,8 +79,8 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -82,8 +79,8 @@ class YHAIMainChatViewController: YHBaseViewController {
return v return v
}() }()
lazy var thinkingMessage: YHAIMessage = { lazy var thinkingMessage: YHAIChatMessage = {
let msg = YHAIMessage.createThinkingMesssage() let msg = YHAIChatMessage.createThinkingMesssage()
return msg return msg
}() }()
......
...@@ -59,7 +59,7 @@ class YHAIRequestManager: NSObject { ...@@ -59,7 +59,7 @@ class YHAIRequestManager: NSObject {
} }
func requestAI(botId: String, conversationId: String, question: String = "", completion: ((_ msg: YHAIMessage?, _ done: Bool) -> Void)?) { func requestAI(botId: String, conversationId: String, question: String = "", completion: ((_ msg: YHAIChatMessage?, _ done: Bool) -> Void)?) {
let url = YHBaseUrlManager.shared.curURL() + YHAllApiName.AIChat.agentChat let url = YHBaseUrlManager.shared.curURL() + YHAllApiName.AIChat.agentChat
self.uuid = UUID().uuidString + NSDate().timeIntervalSince1970.description self.uuid = UUID().uuidString + NSDate().timeIntervalSince1970.description
...@@ -156,7 +156,7 @@ class YHAIRequestManager: NSObject { ...@@ -156,7 +156,7 @@ class YHAIRequestManager: NSObject {
} }
// 处理data字符串 // 处理data字符串
func handle(dataString: String, completion:((_ : YHAIMessage, _ done: Bool) ->())?) { func handle(dataString: String, completion:((_ : YHAIChatMessage, _ done: Bool) ->())?) {
let arr = dataString.components(separatedBy: "\n\n") let arr = dataString.components(separatedBy: "\n\n")
if arr.count <= 0 { if arr.count <= 0 {
...@@ -169,7 +169,7 @@ class YHAIRequestManager: NSObject { ...@@ -169,7 +169,7 @@ class YHAIRequestManager: NSObject {
} }
let lines = text.components(separatedBy: "\n") let lines = text.components(separatedBy: "\n")
if lines.count > 0 { if lines.count > 0 {
let receiveMessage = YHAIMessage() let receiveMessage = YHAIChatMessage()
receiveMessage.uuid = uuid receiveMessage.uuid = uuid
for line in lines { for line in lines {
if line.starts(with: prefix_id) { if line.starts(with: prefix_id) {
......
...@@ -14,7 +14,7 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -14,7 +14,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
var robotId: String = "" var robotId: String = ""
var conversationId: String = "" var conversationId: String = ""
var messages:[YHAIMessage] = [] var messages:[YHAIChatMessage] = []
let manager = YHAIRequestManager() let manager = YHAIRequestManager()
...@@ -48,12 +48,12 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -48,12 +48,12 @@ class YHAIRobotChatViewController: YHBaseViewController {
guard let self = self else { return } guard let self = self else { return }
YHAIChatConfiguration.defaultConfig.removeThinkingMessageFromChatList(&messages) YHAIChatConfiguration.defaultConfig.removeThinkingMessageFromChatList(&messages)
let question = YHAIMessage.createQuestionMessage(text) let question = YHAIChatMessage.createQuestionMessage(text)
messages.append(question) messages.append(question)
messages.append(thinkingMessage) messages.append(thinkingMessage)
self.scrollToBottom() self.scrollToBottom()
self.bottomInputView.status = .loading self.bottomInputView.status = .loading
YHAIChatConfiguration.defaultConfig.disableHandleMessage = true YHAIChatConfiguration.defaultConfig.disableHandleMessage = false
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 }
...@@ -80,8 +80,8 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -80,8 +80,8 @@ class YHAIRobotChatViewController: YHBaseViewController {
return v return v
}() }()
lazy var thinkingMessage: YHAIMessage = { lazy var thinkingMessage: YHAIChatMessage = {
let msg = YHAIMessage.createThinkingMesssage() let msg = YHAIChatMessage.createThinkingMesssage()
return msg return msg
}() }()
......
...@@ -14,15 +14,17 @@ class YHAIMessageModel: NSObject { ...@@ -14,15 +14,17 @@ class YHAIMessageModel: NSObject {
} }
enum YHAIMessageType: Int { enum YHAIMessageType: Int {
case thinking = -1
case thinking = -1 // 思考消息
case none = 0 case none = 0
case text = 1 case AIText = 1 // 文字消息
case fixProductList = 2 case recommendText = 2 // 推荐文字消息
case productList = 3 case fixProductList = 3 // 固定商品列表消息
case card = 4 case productList = 4
case card = 5
} }
class YHAIMessage: CustomStringConvertible { class YHAIChatMessage: CustomStringConvertible {
var id: String = "" var id: String = ""
var event: String = "" var event: String = ""
...@@ -49,8 +51,18 @@ class YHAIMessage: CustomStringConvertible { ...@@ -49,8 +51,18 @@ class YHAIMessage: CustomStringConvertible {
event = "conversation.message.completed" event = "conversation.message.completed"
} }
static func createQuestionMessage(_ text: String) -> YHAIMessage { func isTextMessage() -> Bool {
let question = YHAIMessage() let type = self.getType()
return type == .AIText || type == .recommendText
}
func isNeedSpiceMessage() -> Bool {
let type = self.getType()
return type == .AIText
}
static func createQuestionMessage(_ text: String) -> YHAIChatMessage {
let question = YHAIChatMessage()
question.isSelf = true question.isSelf = true
let body = YHAIMessageBody() let body = YHAIMessageBody()
body.contentType = 1 body.contentType = 1
...@@ -62,8 +74,8 @@ class YHAIMessage: CustomStringConvertible { ...@@ -62,8 +74,8 @@ class YHAIMessage: CustomStringConvertible {
return question return question
} }
static func createThinkingMesssage() -> YHAIMessage { static func createThinkingMesssage() -> YHAIChatMessage {
let message = YHAIMessage() let message = YHAIChatMessage()
message.isSelf = false message.isSelf = false
let body = YHAIMessageBody() let body = YHAIMessageBody()
body.contentType = YHAIMessageType.thinking.rawValue body.contentType = YHAIMessageType.thinking.rawValue
...@@ -81,17 +93,22 @@ class YHAIMessage: CustomStringConvertible { ...@@ -81,17 +93,22 @@ class YHAIMessage: CustomStringConvertible {
// 获取消息类型 // 获取消息类型
func getType() -> YHAIMessageType { func getType() -> YHAIMessageType {
if let type = data["contentType"] as? Int { if let contentType = data["contentType"] as? Int {
if type == YHAIMessageType.thinking.rawValue { if contentType == YHAIMessageType.thinking.rawValue {
return .thinking return .thinking
} }
if type == YHAIMessageType.text.rawValue { if contentType == YHAIMessageType.AIText.rawValue {
return .text if let type = data["type"] as? String {
if type == "follow_up" {
return .recommendText
} }
if type == YHAIMessageType.fixProductList.rawValue { }
return .AIText
}
if contentType == YHAIMessageType.fixProductList.rawValue {
return .fixProductList return .fixProductList
} }
if type == YHAIMessageType.productList.rawValue { if contentType == YHAIMessageType.productList.rawValue {
return .productList return .productList
} }
} }
...@@ -100,7 +117,7 @@ class YHAIMessage: CustomStringConvertible { ...@@ -100,7 +117,7 @@ class YHAIMessage: CustomStringConvertible {
// 获取文字消息的文字 // 获取文字消息的文字
func getText() -> String { func getText() -> String {
if getType() == .text { if getType() == .AIText {
if let text = data["contentText"] as? String, !text.isEmpty { if let text = data["contentText"] as? String, !text.isEmpty {
return text return text
} }
......
...@@ -8,16 +8,16 @@ ...@@ -8,16 +8,16 @@
import UIKit import UIKit
class YHAIMessageCell: UITableViewCell { class YHAITextMessageCell: UITableViewCell {
static let cellReuseIdentifier = "YHAIMessageCell" static let cellReuseIdentifier = "YHAITextMessageCell"
var message: YHAIMessage = YHAIMessage() { var message: YHAIChatMessage = YHAIChatMessage() {
didSet { didSet {
messageLabel.text = message.body.contentText messageLabel.text = message.body.contentText
rightAngleView.backgroundColor = message.isSelf ? .brandMainColor : .white rightAngleView.backgroundColor = message.isSelf ? .brandMainColor : .white
rightAngleView.isHidden = message.getType() != .text rightAngleView.isHidden = message.getType() != .AIText
if message.isSelf { if message.isSelf {
...@@ -41,8 +41,7 @@ class YHAIMessageCell: UITableViewCell { ...@@ -41,8 +41,7 @@ class YHAIMessageCell: UITableViewCell {
} else { } else {
let loadingText = message.isDone ? "" : "..." messageLabel.text = message.body.contentText
messageLabel.text = message.body.contentText + loadingText
whiteContentView.backgroundColor = .white whiteContentView.backgroundColor = .white
messageLabel.textColor = .mainTextColor messageLabel.textColor = .mainTextColor
...@@ -59,8 +58,13 @@ class YHAIMessageCell: UITableViewCell { ...@@ -59,8 +58,13 @@ class YHAIMessageCell: UITableViewCell {
make.width.height.equalTo(15) make.width.height.equalTo(15)
} }
if message.getType() == .recommendText {
isNeedShowCopyView = false
} else {
isNeedShowCopyView = message.isDone isNeedShowCopyView = message.isDone
} }
}
self.setNeedsLayout() self.setNeedsLayout()
self.layoutIfNeeded() self.layoutIfNeeded()
......
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