diff --git a/keyBoard/Class/AiTalk/V/Chat/KBChatTableView.h b/keyBoard/Class/AiTalk/V/Chat/KBChatTableView.h index 96bfd33..80fe4f4 100644 --- a/keyBoard/Class/AiTalk/V/Chat/KBChatTableView.h +++ b/keyBoard/Class/AiTalk/V/Chat/KBChatTableView.h @@ -60,6 +60,9 @@ NS_ASSUME_NONNULL_BEGIN /// 移除 loading AI 消息 - (void)removeLoadingAssistantMessage; +/// 移除 loading 用户消息 +- (void)removeLoadingUserMessage; + /// 滚动到底部 - (void)scrollToBottom; diff --git a/keyBoard/Class/AiTalk/V/Chat/KBChatTableView.m b/keyBoard/Class/AiTalk/V/Chat/KBChatTableView.m index 519ef8a..ec12066 100644 --- a/keyBoard/Class/AiTalk/V/Chat/KBChatTableView.m +++ b/keyBoard/Class/AiTalk/V/Chat/KBChatTableView.m @@ -401,6 +401,32 @@ static inline CGFloat KBChatAbsTimeInterval(NSTimeInterval interval) { } } +- (void)removeLoadingUserMessage { + if (self.inverted) { + for (NSInteger i = 0; i < self.messages.count; i++) { + KBAiChatMessage *message = self.messages[i]; + if (message.type == KBAiChatMessageTypeUser && message.isLoading) { + [self.messages removeObjectAtIndex:i]; + NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0]; + [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; + NSLog(@"[KBChatTableView] 移除 loading 用户消息,索引: %ld", (long)i); + break; + } + } + } else { + for (NSInteger i = self.messages.count - 1; i >= 0; i--) { + KBAiChatMessage *message = self.messages[i]; + if (message.type == KBAiChatMessageTypeUser && message.isLoading) { + [self.messages removeObjectAtIndex:i]; + NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0]; + [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; + NSLog(@"[KBChatTableView] 移除 loading 用户消息,索引: %ld", (long)i); + break; + } + } + } +} + - (void)scrollToBottom { [self scrollToBottomAnimated:YES]; } diff --git a/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.h b/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.h index 96b1e37..fc5c9b9 100644 --- a/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.h +++ b/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.h @@ -36,6 +36,9 @@ NS_ASSUME_NONNULL_BEGIN /// 更新最后一条用户消息 - (void)updateLastUserMessage:(NSString *)text; +/// 移除 loading 用户消息 +- (void)removeLoadingUserMessage; + /// 添加 AI 消息(支持打字机效果) - (void)appendAssistantMessage:(NSString *)text audioId:(nullable NSString *)audioId; diff --git a/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.m b/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.m index 0e49631..a25f209 100644 --- a/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.m +++ b/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.m @@ -637,6 +637,32 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe } } +- (void)removeLoadingUserMessage { + if (!self.messages) { + return; + } + + if (self.chatView.inverted) { + for (NSInteger i = 0; i < self.messages.count; i++) { + KBAiChatMessage *message = self.messages[i]; + if (message.type == KBAiChatMessageTypeUser && message.isLoading) { + [self.messages removeObjectAtIndex:i]; + break; + } + } + } else { + for (NSInteger i = self.messages.count - 1; i >= 0; i--) { + KBAiChatMessage *message = self.messages[i]; + if (message.type == KBAiChatMessageTypeUser && message.isLoading) { + [self.messages removeObjectAtIndex:i]; + break; + } + } + } + + [self.chatView removeLoadingUserMessage]; +} + - (void)markLastUserMessageLoadingComplete { [self.chatView markLastUserMessageLoadingComplete]; diff --git a/keyBoard/Class/AiTalk/VC/KBAIHomeVC.m b/keyBoard/Class/AiTalk/VC/KBAIHomeVC.m index b1f56b7..30e724f 100644 --- a/keyBoard/Class/AiTalk/VC/KBAIHomeVC.m +++ b/keyBoard/Class/AiTalk/VC/KBAIHomeVC.m @@ -959,7 +959,7 @@ NSLog(@"[KBAIHomeVC] 语音转文字结果为空"); [KBHUD showError:KBLocalized(@"未识别到语音内容")]; if (cell) { - [cell updateLastUserMessage:KBLocalized(@"未识别到语音")]; + [cell removeLoadingUserMessage]; } return; }