调用删除接口
This commit is contained in:
@@ -354,6 +354,7 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe
|
||||
|
||||
message.isComplete = YES;
|
||||
message.needsTypewriterEffect = NO;
|
||||
message.historyId = item.messageId;
|
||||
[newMessages addObject:message];
|
||||
// [newMessages insertObject:message atIndex:0];
|
||||
}
|
||||
@@ -931,7 +932,13 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe
|
||||
} break;
|
||||
case KBChatMessageActionTypeDelete: {
|
||||
NSInteger idx = [self.messages indexOfObjectIdenticalTo:message];
|
||||
if (idx != NSNotFound) {
|
||||
if (idx == NSNotFound) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSInteger historyId = message.historyId;
|
||||
// 没有服务端 id 的消息(本地临时/开场白等),直接本地删除即可
|
||||
if (historyId <= 0) {
|
||||
[self.messages removeObjectAtIndex:idx];
|
||||
[self.chatView reloadWithMessages:self.messages
|
||||
keepOffset:YES
|
||||
@@ -944,7 +951,44 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe
|
||||
[[KBAIChatMessageCacheManager shared] clearMessagesForCompanionId:self.persona.personaId];
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
[KBHUD show];
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.aiVM deleteChatHistoryWithId:historyId completion:^(BOOL success, NSError * _Nullable error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[KBHUD dismiss];
|
||||
if (!success || error) {
|
||||
NSString *msg = error.localizedDescription ?: KBLocalized(@"删除失败,请重试");
|
||||
[KBHUD showError:msg];
|
||||
return;
|
||||
}
|
||||
|
||||
__strong typeof(weakSelf) strongSelf = weakSelf;
|
||||
if (!strongSelf) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSInteger idx2 = [strongSelf.messages indexOfObjectIdenticalTo:message];
|
||||
if (idx2 == NSNotFound) {
|
||||
return;
|
||||
}
|
||||
|
||||
[strongSelf.messages removeObjectAtIndex:idx2];
|
||||
[strongSelf.chatView reloadWithMessages:strongSelf.messages
|
||||
keepOffset:YES
|
||||
scrollToBottom:NO];
|
||||
if (strongSelf.persona.personaId > 0) {
|
||||
if (strongSelf.messages.count > 0) {
|
||||
[[KBAIChatMessageCacheManager shared] saveMessages:strongSelf.messages
|
||||
forCompanionId:strongSelf.persona.personaId];
|
||||
} else {
|
||||
[[KBAIChatMessageCacheManager shared] clearMessagesForCompanionId:strongSelf.persona.personaId];
|
||||
}
|
||||
}
|
||||
});
|
||||
}];
|
||||
} break;
|
||||
case KBChatMessageActionTypeReport: {
|
||||
if (self.persona.personaId <= 0) {
|
||||
|
||||
Reference in New Issue
Block a user