处理键盘bug
This commit is contained in:
@@ -855,8 +855,7 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
|
||||
if (text.length == 0) {
|
||||
return;
|
||||
}
|
||||
NSLog(@"[Keyboard] ========== kb_sendChatText ==========");
|
||||
NSLog(@"[Keyboard] chatPanelView=%p", self.chatPanelView);
|
||||
NSLog(@"[KB] 发送消息: %@", text);
|
||||
|
||||
KBChatMessage *outgoing = [KBChatMessage userMessageWithText:text];
|
||||
outgoing.avatarURL = [self kb_sharedUserAvatarURL];
|
||||
@@ -869,7 +868,6 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
|
||||
}
|
||||
|
||||
// 添加 loading 消息
|
||||
NSLog(@"[Keyboard] 准备添加 loading 消息,chatPanelView=%p", self.chatPanelView);
|
||||
[self.chatPanelView kb_addLoadingAssistantMessage];
|
||||
|
||||
// 调用新的聊天接口
|
||||
@@ -932,16 +930,9 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
|
||||
}
|
||||
|
||||
- (void)kb_reloadChatRowForMessage:(KBChatMessage *)message {
|
||||
NSLog(@"[Keyboard] ========== kb_reloadChatRowForMessage ==========");
|
||||
// 不再使用 self.chatMessages,直接刷新 tableView
|
||||
UITableView *tableView = self.chatPanelView.tableView;
|
||||
if (!tableView) {
|
||||
NSLog(@"[Keyboard] tableView 为空,跳过");
|
||||
return;
|
||||
}
|
||||
// 刷新整个 tableView
|
||||
NSLog(@"[Keyboard] 调用 tableView reloadData");
|
||||
[tableView reloadData];
|
||||
// 头像预加载完成后不需要刷新表格
|
||||
// 因为键盘扩展的聊天面板不显示头像,所以这里直接返回
|
||||
// 如果将来需要显示头像,可以只刷新特定行而不是整个表格
|
||||
}
|
||||
|
||||
- (void)kb_requestChatAudioForText:(NSString *)text {
|
||||
@@ -1011,51 +1002,40 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
|
||||
|
||||
/// 调用新的聊天接口(返回文本和 audioId)
|
||||
- (void)kb_requestChatMessageWithContent:(NSString *)content {
|
||||
NSLog(@"[Keyboard] ========== kb_requestChatMessageWithContent ==========");
|
||||
NSLog(@"[Keyboard] 请求内容: %@", content);
|
||||
|
||||
if (content.length == 0) {
|
||||
NSLog(@"[Keyboard] ❌ 内容为空,移除 loading");
|
||||
[self.chatPanelView kb_removeLoadingAssistantMessage];
|
||||
return;
|
||||
}
|
||||
|
||||
// 从 AppGroup 获取选中的 persona companionId
|
||||
NSInteger companionId = [[KBVM shared] selectedCompanionIdFromAppGroup];
|
||||
NSLog(@"[Keyboard] 发送聊天请求: companionId=%ld", (long)companionId);
|
||||
NSLog(@"[KB] 请求聊天: companionId=%ld", (long)companionId);
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[[KBVM shared] sendChatMessageWithContent:content
|
||||
companionId:companionId
|
||||
completion:^(KBChatResponse *response) {
|
||||
__strong typeof(weakSelf) self = weakSelf;
|
||||
if (!self) {
|
||||
NSLog(@"[Keyboard] ❌ self 为空");
|
||||
return;
|
||||
}
|
||||
|
||||
NSLog(@"[Keyboard] 回调中 chatPanelView=%p", self.chatPanelView);
|
||||
if (!self) return;
|
||||
|
||||
if (!response.success) {
|
||||
NSLog(@"[Keyboard] ❌ 请求失败: %@", response.errorMessage);
|
||||
NSLog(@"[KB] ❌ 请求失败: %@", response.errorMessage);
|
||||
[self.chatPanelView kb_removeLoadingAssistantMessage];
|
||||
[KBHUD showInfo:response.errorMessage ?: KBLocalized(@"请求失败")];
|
||||
return;
|
||||
}
|
||||
|
||||
NSLog(@"[Keyboard] ✅ 解析结果: text=%@, audioId=%@", response.text, response.audioId);
|
||||
NSLog(@"[KB] ✅ 收到回复: %@", response.text);
|
||||
|
||||
if (response.text.length == 0) {
|
||||
NSLog(@"[Keyboard] ❌ 文本为空,移除 loading");
|
||||
[self.chatPanelView kb_removeLoadingAssistantMessage];
|
||||
[KBHUD showInfo:KBLocalized(@"未获取到回复内容")];
|
||||
return;
|
||||
}
|
||||
|
||||
NSLog(@"[Keyboard] 准备调用 kb_addAssistantMessage, chatPanelView=%p", self.chatPanelView);
|
||||
// 添加 AI 消息(带打字机效果)
|
||||
NSLog(@"[KB] 准备添加 AI 消息");
|
||||
[self.chatPanelView kb_addAssistantMessage:response.text audioId:response.audioId];
|
||||
NSLog(@"[Keyboard] kb_addAssistantMessage 调用完成");
|
||||
NSLog(@"[KB] AI 消息添加完成");
|
||||
|
||||
// 如果有 audioId,开始预加载音频
|
||||
if (response.audioId.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user