调用删除接口
This commit is contained in:
@@ -22,6 +22,9 @@ typedef NS_ENUM(NSInteger, KBAiChatMessageType) {
|
|||||||
/// 消息类型
|
/// 消息类型
|
||||||
@property (nonatomic, assign) KBAiChatMessageType type;
|
@property (nonatomic, assign) KBAiChatMessageType type;
|
||||||
|
|
||||||
|
/// 聊天记录 ID(服务端返回的 id,用于删除等操作;0 表示本地临时消息)
|
||||||
|
@property (nonatomic, assign) NSInteger historyId;
|
||||||
|
|
||||||
/// 文本内容
|
/// 文本内容
|
||||||
@property (nonatomic, copy) NSString *text;
|
@property (nonatomic, copy) NSString *text;
|
||||||
|
|
||||||
|
|||||||
@@ -354,6 +354,7 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe
|
|||||||
|
|
||||||
message.isComplete = YES;
|
message.isComplete = YES;
|
||||||
message.needsTypewriterEffect = NO;
|
message.needsTypewriterEffect = NO;
|
||||||
|
message.historyId = item.messageId;
|
||||||
[newMessages addObject:message];
|
[newMessages addObject:message];
|
||||||
// [newMessages insertObject:message atIndex:0];
|
// [newMessages insertObject:message atIndex:0];
|
||||||
}
|
}
|
||||||
@@ -931,7 +932,13 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe
|
|||||||
} break;
|
} break;
|
||||||
case KBChatMessageActionTypeDelete: {
|
case KBChatMessageActionTypeDelete: {
|
||||||
NSInteger idx = [self.messages indexOfObjectIdenticalTo:message];
|
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.messages removeObjectAtIndex:idx];
|
||||||
[self.chatView reloadWithMessages:self.messages
|
[self.chatView reloadWithMessages:self.messages
|
||||||
keepOffset:YES
|
keepOffset:YES
|
||||||
@@ -944,7 +951,44 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe
|
|||||||
[[KBAIChatMessageCacheManager shared] clearMessagesForCompanionId:self.persona.personaId];
|
[[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;
|
} break;
|
||||||
case KBChatMessageActionTypeReport: {
|
case KBChatMessageActionTypeReport: {
|
||||||
if (self.persona.personaId <= 0) {
|
if (self.persona.personaId <= 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user