Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
galaxy-iOS
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mobile-group
galaxy-iOS
Commits
90587ce2
Commit
90587ce2
authored
Dec 11, 2024
by
Steven杜宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
// AI
parent
0a544f2e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
66 deletions
+66
-66
YHAIMainChatViewController.swift
...s/AI/AI-Dialogue(AI对话)/C/YHAIMainChatViewController.swift
+15
-19
YHAIRequestManager.swift
...s/Modules/AI/AI-Dialogue(AI对话)/C/YHAIRequestManager.swift
+31
-27
YHAIRobotChatViewController.swift
.../AI/AI-Dialogue(AI对话)/C/YHAIRobotChatViewController.swift
+14
-18
YHAITextMessageCell.swift
.../Modules/AI/AI-Dialogue(AI对话)/V/YHAITextMessageCell.swift
+6
-2
No files found.
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAIMainChatViewController.swift
View file @
90587ce2
...
...
@@ -18,11 +18,7 @@ class YHAIMainChatViewController: YHBaseViewController {
var
isNeedAutoResponseImage
=
false
var
isHaveAutoResponseText
=
false
var
messages
:[
YHAIChatMessage
]
=
[]
var
isUserScrolling
:
Bool
=
false
var
lastUserScrollTime
:
CFTimeInterval
=
0.0
let
minimumScrollInterval
:
CFTimeInterval
=
2.0
var
disableScrollToBottom
:
Bool
=
false
let
manager
=
YHAIRequestManager
()
let
viewModel
=
YHAIViewModel
()
...
...
@@ -111,11 +107,11 @@ class YHAIMainChatViewController: YHBaseViewController {
self
.
bottomInputView
.
showKeyBoard
(
false
)
}
func
reloadAndScrollToBottom
(
_
forceScrollToBottom
:
Bool
=
false
,
_
isNeedAccurate
:
Bool
=
false
)
{
func
reloadAndScrollToBottom
()
{
self
.
tableView
.
reloadData
()
if
!
forceScrollToBottom
&&
!
canTriggerProgrammaticScroll
()
{
if
canTriggerProgrammaticScroll
()
{
return
}
...
...
@@ -148,10 +144,11 @@ class YHAIMainChatViewController: YHBaseViewController {
let
question
=
YHAIChatMessage
.
createQuestionMessage
(
text
)
self
.
messages
.
append
(
question
)
self
.
messages
.
append
(
self
.
thinkingMessage
)
self
.
reloadAndScrollToBottom
(
forceScrollToBottom
)
self
.
reloadAndScrollToBottom
()
self
.
bottomInputView
.
status
=
.
loading
self
.
chatConfig
.
disableHandleMessage
=
false
self
.
manager
.
disableHandleMessage
=
false
self
.
disableScrollToBottom
=
false
self
.
manager
.
requestAI
(
botId
:
self
.
robotId
,
conversationId
:
self
.
conversationId
,
question
:
text
)
{
[
weak
self
]
res
,
done
in
guard
let
self
=
self
else
{
return
}
...
...
@@ -160,7 +157,7 @@ class YHAIMainChatViewController: YHBaseViewController {
print
(
"RESPONSE-DONE"
)
self
.
bottomInputView
.
status
=
self
.
bottomInputView
.
textView
.
text
.
isEmpty
?
.
disableSend
:
.
enableSend
}
self
.
reloadAndScrollToBottom
(
forceScrollToBottom
)
self
.
reloadAndScrollToBottom
()
}
}
}
...
...
@@ -185,7 +182,7 @@ class YHAIMainChatViewController: YHBaseViewController {
}
messages
.
insert
(
contentsOf
:
results
,
at
:
0
)
autoResponseTextMessage
()
self
.
reloadAndScrollToBottom
(
true
,
true
)
self
.
reloadAndScrollToBottom
()
}
}
...
...
@@ -264,6 +261,8 @@ extension YHAIMainChatViewController: UITableViewDelegate, UITableViewDataSource
cell
.
messageClick
=
{
[
weak
self
]
text
in
guard
let
self
=
self
else
{
return
}
self
.
bottomInputView
.
showKeyBoard
(
false
)
if
self
.
isNeedStopResonse
()
{
self
.
stopAutoResponse
{
success
in
self
.
sendMessage
(
text
)
...
...
@@ -350,7 +349,7 @@ extension YHAIMainChatViewController: UITableViewDelegate, UITableViewDataSource
if
0
<=
indexPath
.
row
,
indexPath
.
row
<
messages
.
count
{
let
message
=
messages
[
indexPath
.
row
]
let
msgType
=
message
.
getType
()
if
!
message
.
isTextMessage
()
{
if
msgType
!=
.
text
{
return
UITableView
.
automaticDimension
}
...
...
@@ -366,7 +365,7 @@ extension YHAIMainChatViewController: UITableViewDelegate, UITableViewDataSource
textHeight
=
20.0
}
if
message
.
isSelf
||
msgType
==
.
recommendText
{
if
message
.
isSelf
{
return
textHeight
+
16.0
*
2
+
16.0
}
...
...
@@ -405,25 +404,22 @@ extension YHAIMainChatViewController: UITableViewDelegate, UITableViewDataSource
}
func
scrollViewWillBeginDragging
(
_
scrollView
:
UIScrollView
)
{
isUserScrolling
=
true
lastUserScrollTime
=
CACurrentMediaTime
(
)
disableScrollToBottom
=
true
self
.
bottomInputView
.
showKeyBoard
(
false
)
}
func
scrollViewDidEndDragging
(
_
scrollView
:
UIScrollView
,
willDecelerate
decelerate
:
Bool
)
{
if
!
decelerate
{
isUserScrolling
=
false
}
}
func
scrollViewDidEndDecelerating
(
_
scrollView
:
UIScrollView
)
{
isUserScrolling
=
false
lastUserScrollTime
=
CACurrentMediaTime
()
}
// 检查是否可以执行代码触发的滚动
func
canTriggerProgrammaticScroll
()
->
Bool
{
let
currentTime
=
CACurrentMediaTime
()
return
(
currentTime
-
lastUserScrollTime
)
>=
minimumScrollInterval
return
!
disableScrollToBottom
}
}
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAIRequestManager.swift
View file @
90587ce2
...
...
@@ -245,40 +245,44 @@ class YHAIRequestManager: NSObject {
self
.
uuid
=
UUID
()
.
uuidString
+
NSDate
()
.
timeIntervalSince1970
.
description
}
// if receiveMessage.isUserfulMessage() {
// if receiveMessage.body.isDone() {
// completion?(nil, sessionDone)
// } else {
// completion?(receiveMessage, sessionDone)
// }
// }
if
receiveMessage
.
isUserfulMessage
()
{
if
receiveMessage
.
body
.
isDone
()
{
completion
?(
nil
,
sessionDone
)
return
}
if
receiveMessage
.
isNeedSpiceMessage
()
{
let
text
=
receiveMessage
.
body
.
contentText
if
text
.
count
>
1
{
let
textArray
=
Array
(
text
)
for
(
index
,
character
)
in
textArray
.
enumerated
()
{
let
msg
=
receiveMessage
.
copy
()
as!
YHAIChatMessage
msg
.
body
.
contentText
=
String
(
character
)
msg
.
body
.
status
=
""
if
index
==
textArray
.
count
-
1
{
msg
.
body
.
status
=
receiveMessage
.
body
.
status
}
msg
.
updateBodyToData
()
printLog
(
"AAAAA-
\(
msg
)
"
)
sessionDone
=
receiveMessage
.
body
.
isDone
()
completion
?(
msg
,
sessionDone
)
}
}
else
{
completion
?(
receiveMessage
,
sessionDone
)
}
}
else
{
completion
?(
receiveMessage
,
sessionDone
)
}
}
// if receiveMessage.isUserfulMessage() {
// if receiveMessage.isNeedSpiceMessage() {
// let text = receiveMessage.body.contentText
// if text.count > 1 {
// let textArray = Array(text)
// for (index, character) in textArray.enumerated() {
// let msg = receiveMessage.copy() as! YHAIChatMessage
// msg.body.contentText = String(character)
// msg.body.status = ""
// if index == textArray.count-1 {
// msg.body.status = receiveMessage.body.status
// }
// msg.updateBodyToData()
// printLog("AAAAA- \(msg)")
// sessionDone = receiveMessage.body.isDone()
// completion?(msg, sessionDone)
// }
//
// } else {
// completion?(receiveMessage, sessionDone)
// }
//
// } else {
// completion?(receiveMessage, sessionDone)
// }
// }
}
}
// arr 结束
}
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAIRobotChatViewController.swift
View file @
90587ce2
...
...
@@ -15,9 +15,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
var
myTitle
:
String
=
""
var
robotId
:
String
=
""
var
listItemId
:
Int
=
0
var
isUserScrolling
:
Bool
=
false
var
lastUserScrollTime
:
CFTimeInterval
=
0.0
let
minimumScrollInterval
:
CFTimeInterval
=
2.0
var
disableScrollToBottom
:
Bool
=
false
var
conversationId
:
String
=
""
var
messages
:[
YHAIChatMessage
]
=
[]
var
isNeedShowBannerHeader
:
Bool
=
false
...
...
@@ -181,11 +179,11 @@ class YHAIRobotChatViewController: YHBaseViewController {
self
.
navigationController
?
.
popViewController
(
animated
:
true
)
}
func
reloadAndScrollToBottom
(
_
forceScrollToBottom
:
Bool
=
false
,
_
isNeedAccurate
:
Bool
=
false
)
{
func
reloadAndScrollToBottom
()
{
self
.
tableView
.
reloadData
()
if
!
forceScrollToBottom
&&
!
canTriggerProgrammaticScroll
()
{
if
canTriggerProgrammaticScroll
()
{
return
}
...
...
@@ -219,7 +217,8 @@ class YHAIRobotChatViewController: YHBaseViewController {
self
.
bottomInputView
.
status
=
.
loading
self
.
chatConfig
.
disableHandleMessage
=
false
self
.
manager
.
disableHandleMessage
=
false
self
.
reloadAndScrollToBottom
(
forceScrollToBottom
)
self
.
disableScrollToBottom
=
false
self
.
reloadAndScrollToBottom
()
self
.
manager
.
requestAI
(
botId
:
self
.
robotId
,
conversationId
:
self
.
conversationId
,
question
:
text
)
{
[
weak
self
]
res
,
done
in
...
...
@@ -229,7 +228,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
print
(
"RESPONSE-DONE"
)
self
.
bottomInputView
.
status
=
self
.
bottomInputView
.
textView
.
text
.
isEmpty
?
.
disableSend
:
.
enableSend
}
self
.
reloadAndScrollToBottom
(
forceScrollToBottom
)
self
.
reloadAndScrollToBottom
()
}
}
...
...
@@ -251,7 +250,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
return
!
uuids
.
contains
(
$0
.
messageId
)
}
messages
.
insert
(
contentsOf
:
results
,
at
:
0
)
reloadAndScrollToBottom
(
true
,
true
)
reloadAndScrollToBottom
()
autoResponseLocalTextMessage
()
}
...
...
@@ -276,7 +275,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
let
msg
=
self
.
chatConfig
.
createRobotResponseLocalPictureMessage
(
"ai_auto_chat_img"
,
previewUrl
:
previewUrl
)
messages
.
append
(
msg
)
}
self
.
reloadAndScrollToBottom
(
true
)
self
.
reloadAndScrollToBottom
()
}
func
uploadEvaluationMessage
(
_
msg
:
YHAIChatMessage
,
callback
:((
Bool
)
->
())?
=
nil
)
{
...
...
@@ -490,7 +489,7 @@ extension YHAIRobotChatViewController: UITableViewDelegate, UITableViewDataSourc
if
0
<=
indexPath
.
row
,
indexPath
.
row
<
messages
.
count
{
let
message
=
messages
[
indexPath
.
row
]
let
msgType
=
message
.
getType
()
if
!
message
.
isTextMessage
()
{
if
msgType
!=
.
text
{
return
UITableView
.
automaticDimension
}
...
...
@@ -506,7 +505,7 @@ extension YHAIRobotChatViewController: UITableViewDelegate, UITableViewDataSourc
textHeight
=
20.0
}
if
message
.
isSelf
||
msgType
==
.
recommendText
{
if
message
.
isSelf
{
return
textHeight
+
16.0
*
2
+
16.0
}
...
...
@@ -550,25 +549,22 @@ extension YHAIRobotChatViewController: UITableViewDelegate, UITableViewDataSourc
}
func
scrollViewWillBeginDragging
(
_
scrollView
:
UIScrollView
)
{
isUserScrolling
=
true
lastUserScrollTime
=
CACurrentMediaTime
(
)
disableScrollToBottom
=
true
self
.
bottomInputView
.
showKeyBoard
(
false
)
}
func
scrollViewDidEndDragging
(
_
scrollView
:
UIScrollView
,
willDecelerate
decelerate
:
Bool
)
{
if
!
decelerate
{
isUserScrolling
=
false
}
}
func
scrollViewDidEndDecelerating
(
_
scrollView
:
UIScrollView
)
{
isUserScrolling
=
false
lastUserScrollTime
=
CACurrentMediaTime
()
}
// 检查是否可以执行代码触发的滚动
func
canTriggerProgrammaticScroll
()
->
Bool
{
let
currentTime
=
CACurrentMediaTime
()
return
(
currentTime
-
lastUserScrollTime
)
>=
minimumScrollInterval
return
!
disableScrollToBottom
}
}
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/V/YHAITextMessageCell.swift
View file @
90587ce2
...
...
@@ -52,7 +52,11 @@ class YHAITextMessageCell: UITableViewCell {
whiteContentView
.
snp
.
remakeConstraints
{
make
in
make
.
left
.
equalTo
(
20
)
make
.
right
.
equalTo
(
-
20
)
if
message
.
getType
()
==
.
recommendText
{
make
.
right
.
lessThanOrEqualTo
(
-
20
)
}
else
{
make
.
right
.
equalTo
(
-
20
)
}
make
.
top
.
equalTo
(
16
)
make
.
bottom
.
equalTo
(
0
)
}
...
...
@@ -263,7 +267,7 @@ class YHAITextMessageCell: UITableViewCell {
@objc
func
didMessageClicked
()
{
self
.
endEditing
(
true
)
UIApplication
.
shared
.
yhKeyWindow
()?
.
endEditing
(
true
)
if
message
.
getType
()
==
.
recommendText
{
let
text
=
message
.
getText
()
messageClick
?(
text
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment