This commit is contained in:
2026-01-28 19:31:27 +08:00
parent 66d85f78a0
commit 70a8466d9f
10 changed files with 180 additions and 35 deletions

View File

@@ -16,6 +16,9 @@
#import <SDWebImage/SDWebImage.h>
#import <LSTPopView/LSTPopView.h>
///
static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidResetNotification";
@interface KBPersonaChatCell () <KBChatTableViewDelegate>
///
@@ -68,10 +71,20 @@
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self setupUI];
//
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleChatSessionReset:)
name:KBChatSessionDidResetNotification
object:nil];
}
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
/// Cell
- (void)prepareForReuse {
[super prepareForReuse];
@@ -192,8 +205,8 @@
//
if (self.messages.count > 0) {
[self.chatView reloadWithMessages:self.messages
hasMoreHistory:self.hasMoreHistory
completion:nil];
keepOffset:NO
scrollToBottom:YES];
} else {
[self.chatView clearMessages];
}
@@ -331,6 +344,37 @@
});
}
#pragma mark -
///
- (void)handleChatSessionReset:(NSNotification *)notification {
NSNumber *companionIdObj = notification.userInfo[@"companionId"];
if (!companionIdObj) {
return;
}
NSInteger companionId = [companionIdObj integerValue];
//
if (self.persona && self.persona.personaId == companionId) {
NSLog(@"[KBPersonaChatCell] 收到聊天重置通知companionId=%ld, 清空聊天记录", (long)companionId);
//
self.messages = [NSMutableArray array];
self.hasLoadedData = NO;
self.currentPage = 1;
self.hasMoreHistory = YES;
//
[self.chatView clearMessages];
//
if (self.persona.introText.length > 0) {
[self showOpeningMessage];
}
}
}
#pragma mark - 3
- (void)appendUserMessage:(NSString *)text {