处理滚动底部问题
This commit is contained in:
@@ -647,6 +647,12 @@
|
||||
unsigned long long fileSize = [attributes[NSFileSize] unsignedLongLongValue];
|
||||
NSLog(@"[KBAIHomeVC] 录音完成,时长: %.2fs,大小: %llu bytes", duration, fileSize);
|
||||
|
||||
// 显示 loading 气泡
|
||||
KBPersonaChatCell *currentCell = [self currentPersonaCell];
|
||||
if (currentCell) {
|
||||
[currentCell appendLoadingUserMessage];
|
||||
}
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.aiVM transcribeAudioFileAtURL:fileURL
|
||||
completion:^(KBAiSpeechTranscribeResponse * _Nullable response, NSError * _Nullable error) {
|
||||
@@ -656,9 +662,14 @@
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
KBPersonaChatCell *cell = [strongSelf currentPersonaCell];
|
||||
|
||||
if (error) {
|
||||
NSLog(@"[KBAIHomeVC] 语音转文字失败:%@", error.localizedDescription);
|
||||
[KBHUD showError:KBLocalized(@"语音转文字失败,请重试")];
|
||||
if (cell) {
|
||||
[cell updateLastUserMessage:KBLocalized(@"语音识别失败")];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -666,10 +677,19 @@
|
||||
if (transcript.length == 0) {
|
||||
NSLog(@"[KBAIHomeVC] 语音转文字结果为空");
|
||||
[KBHUD showError:KBLocalized(@"未识别到语音内容")];
|
||||
if (cell) {
|
||||
[cell updateLastUserMessage:KBLocalized(@"未识别到语音")];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
[strongSelf handleTranscribedText:transcript];
|
||||
// 更新 loading 气泡为实际文本
|
||||
if (cell) {
|
||||
[cell updateLastUserMessage:transcript];
|
||||
}
|
||||
|
||||
// 发送聊天请求(不追加消息,因为已经更新了)
|
||||
[strongSelf handleTranscribedText:transcript appendToUI:NO];
|
||||
});
|
||||
}];
|
||||
}
|
||||
@@ -687,6 +707,10 @@
|
||||
#pragma mark - Private
|
||||
|
||||
- (void)handleTranscribedText:(NSString *)text {
|
||||
[self handleTranscribedText:text appendToUI:YES];
|
||||
}
|
||||
|
||||
- (void)handleTranscribedText:(NSString *)text appendToUI:(BOOL)appendToUI {
|
||||
if (text.length == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -699,7 +723,7 @@
|
||||
}
|
||||
|
||||
KBPersonaChatCell *currentCell = [self currentPersonaCell];
|
||||
if (currentCell) {
|
||||
if (currentCell && appendToUI) {
|
||||
[currentCell appendUserMessage:text];
|
||||
}
|
||||
|
||||
@@ -722,6 +746,12 @@
|
||||
strongSelf.isWaitingForAIResponse = NO;
|
||||
strongSelf.collectionView.scrollEnabled = YES;
|
||||
NSLog(@"[KBAIHomeVC] AI 回复完成,恢复 CollectionView 滚动");
|
||||
|
||||
// 收到响应后,隐藏用户消息的 loading
|
||||
KBPersonaChatCell *cell = [strongSelf currentPersonaCell];
|
||||
if (cell) {
|
||||
[cell markLastUserMessageLoadingComplete];
|
||||
}
|
||||
|
||||
if (response.code == 50030) {
|
||||
NSString *message = response.message ?: @"";
|
||||
@@ -745,7 +775,6 @@
|
||||
return;
|
||||
}
|
||||
|
||||
KBPersonaChatCell *cell = [strongSelf currentPersonaCell];
|
||||
if (cell) {
|
||||
[cell appendAssistantMessage:aiResponse audioId:audioId];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user