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

@@ -110,7 +110,7 @@
#pragma mark - 1
- (void)setupUI {
self.voiceInputBarHeight = 120.0;
self.voiceInputBarHeight = 80.0;
self.baseInputBarBottomSpacing = KB_TABBAR_HEIGHT;
[self.view addSubview:self.collectionView];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {

View File

@@ -9,8 +9,12 @@
#import "AiVM.h"
#import "KBChattedCompanionModel.h"
#import "KBHUD.h"
#import "KBAIChatMessageCacheManager.h"
#import <Masonry/Masonry.h>
///
static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidResetNotification";
@interface KBAIMessageChatingVC ()
@property (nonatomic, strong) AiVM *viewModel;
@@ -54,10 +58,11 @@
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];
if (indexPath) {
self.longPressIndexPath = indexPath;
//
[self showDeleteButtonAtPoint:point];
// showDeleteButtonAtPoint hideDeleteButton
self.longPressIndexPath = indexPath;
}
}
}
@@ -65,12 +70,14 @@
- (void)handleTapGesture:(UITapGestureRecognizer *)gesture {
//
if (self.deleteButton && !self.deleteButton.hidden) {
CGPoint point = [gesture locationInView:self.view];
CGPoint buttonPoint = [gesture locationInView:self.deleteButton];
CGPoint pointInButton = [gesture locationInView:self.deleteButton];
//
if (!CGRectContainsPoint(self.deleteButton.bounds, buttonPoint)) {
if (!CGRectContainsPoint(self.deleteButton.bounds, pointInButton)) {
NSLog(@"[KBAIMessageChatingVC] 点击了删除按钮外部,隐藏按钮");
[self hideDeleteButton];
} else {
NSLog(@"[KBAIMessageChatingVC] 点击了删除按钮内部,不隐藏");
}
}
}
@@ -155,13 +162,75 @@
}
- (void)deleteButtonTapped {
if (self.longPressIndexPath) {
//
[self hideDeleteButton];
//
[self deleteItemAtIndexPath:self.longPressIndexPath];
if (!self.longPressIndexPath) {
return;
}
// indexPath
NSIndexPath *indexPath = self.longPressIndexPath;
//
if (indexPath.row >= self.chattedList.count) {
NSLog(@"[KBAIMessageChatingVC] 错误索引越界row=%ld, count=%ld",
(long)indexPath.row, (long)self.chattedList.count);
[self hideDeleteButton];
return;
}
KBChattedCompanionModel *model = self.chattedList[indexPath.row];
NSInteger companionId = model.companionId;
NSLog(@"[KBAIMessageChatingVC] 开始删除聊天记录companionId=%ld, name=%@",
(long)companionId, model.name);
//
[self hideDeleteButton];
//
[KBHUD show];
__weak typeof(self) weakSelf = self;
// API
[self.viewModel resetChatSessionWithCompanionId:companionId
completion:^(KBChatSessionResetResponse * _Nullable response, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
[KBHUD dismiss];
if (error) {
NSLog(@"[KBAIMessageChatingVC] 删除失败:%@", error.localizedDescription);
[KBHUD showError:@"删除失败,请重试"];
return;
}
NSLog(@"[KBAIMessageChatingVC] ✅ API 调用成功,开始清理本地数据");
// 1.
if (indexPath.row < weakSelf.chattedList.count) {
[weakSelf.chattedList removeObjectAtIndex:indexPath.row];
}
if (indexPath.row < weakSelf.dataArray.count) {
[weakSelf.dataArray removeObjectAtIndex:indexPath.row];
}
// 2. TableView
[weakSelf.tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationLeft];
// 3.
[[KBAIChatMessageCacheManager shared] clearMessagesForCompanionId:companionId];
NSLog(@"[KBAIMessageChatingVC] ✅ 已清除缓存companionId=%ld", (long)companionId);
// 4.
[[NSNotificationCenter defaultCenter] postNotificationName:KBChatSessionDidResetNotification
object:nil
userInfo:@{@"companionId": @(companionId)}];
NSLog(@"[KBAIMessageChatingVC] ✅ 已发送重置通知companionId=%ld", (long)companionId);
// 5.
[KBHUD showSuccess:@"已删除"];
});
}];
}
#pragma mark - 2
@@ -200,24 +269,6 @@
}];
}
#pragma mark -
- (void)deleteItemAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row >= self.chattedList.count) {
return;
}
// TODO:
//
if (indexPath.row < self.chattedList.count) {
[self.chattedList removeObjectAtIndex:indexPath.row];
}
if (indexPath.row < self.dataArray.count) {
[self.dataArray removeObjectAtIndex:indexPath.row];
}
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
#pragma mark - Lazy Load
- (AiVM *)viewModel {

View File

@@ -19,7 +19,7 @@
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.view.backgroundColor = [UIColor clearColor];
/// 1
[self setupUI];
@@ -130,7 +130,7 @@
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = [UIColor whiteColor];
_tableView.backgroundColor = [UIColor clearColor];
_tableView.showsVerticalScrollIndicator = NO;
[_tableView registerClass:[KBAIMessageCell class] forCellReuseIdentifier:@"KBAIMessageCell"];

View File

@@ -13,6 +13,9 @@
@interface KBAIMessageVC () <JXCategoryViewDelegate, JXCategoryListContainerViewDelegate>
///
@property (nonatomic, strong) UIImageView *backgroundImageView;
///
@property (nonatomic, strong) JXCategoryTitleView *categoryView;
@@ -45,6 +48,14 @@
#pragma mark - 1
- (void)setupUI {
//
// [self.view addSubview:self.backgroundImageView];
self.kb_navView.backgroundColor = [UIColor clearColor];
[self.view insertSubview:self.backgroundImageView belowSubview:self.kb_navView];
[self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
//
self.kb_titleLabel.hidden = YES;
@@ -74,6 +85,7 @@
// categoryView listContainerView
self.categoryView.listContainer = self.listContainerView;
self.listContainerView.backgroundColor = [UIColor clearColor];
// tab (Thumbs Up)
// self.listContainerView.scrollView.scrollEnabled = YES;
@@ -115,6 +127,16 @@
#pragma mark - Lazy Load
- (UIImageView *)backgroundImageView {
if (!_backgroundImageView) {
_backgroundImageView = [[UIImageView alloc] init];
_backgroundImageView.image = [UIImage imageNamed:@"message_bg_icon"];
_backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
_backgroundImageView.clipsToBounds = YES;
}
return _backgroundImageView;
}
- (NSArray<NSString *> *)titles {
if (!_titles) {
_titles = @[KBLocalized(@"Thumbs Up"), KBLocalized(@"Chatting")];