1
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user