// // KBAIMessageZanVC.m // keyBoard // // Created by Mac on 2026/1/28. // #import "KBAIMessageZanVC.h" #import "AiVM.h" #import "KBLikedCompanionModel.h" #import "KBHUD.h" @interface KBAIMessageZanVC () @property (nonatomic, strong) AiVM *viewModel; @property (nonatomic, strong) NSMutableArray *likedList; @end @implementation KBAIMessageZanVC #pragma mark - Lifecycle - (void)viewDidLoad { self.listType = 0; // Thumbs Up [super viewDidLoad]; } #pragma mark - UITableViewDelegate Override // Thumbs Up tab 不需要左滑删除功能 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return NO; // 禁用左滑删除 } - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) { return nil; // 不显示滑动操作 } #pragma mark - 2:数据加载 - (void)loadData { [KBHUD show]; __weak typeof(self) weakSelf = self; [self.viewModel fetchLikedCompanionsWithCompletion:^(NSArray * _Nullable list, NSError * _Nullable error) { dispatch_async(dispatch_get_main_queue(), ^{ [KBHUD dismiss]; if (error) { [KBHUD showError:error.localizedDescription]; return; } [weakSelf.likedList removeAllObjects]; if (list.count > 0) { [weakSelf.likedList addObjectsFromArray:list]; } [weakSelf.dataArray removeAllObjects]; // 转换为通用数据格式 for (KBLikedCompanionModel *model in weakSelf.likedList) { NSMutableDictionary *item = [NSMutableDictionary dictionary]; item[@"avatar"] = model.avatarUrl ?: @""; item[@"name"] = model.name ?: @""; item[@"content"] = model.shortDesc ?: @""; item[@"time"] = model.createdAt ?: @""; item[@"isPinned"] = @NO; item[@"companionId"] = @(model.companionId); [weakSelf.dataArray addObject:item]; } [weakSelf.tableView reloadData]; }); }]; } #pragma mark - 删除 - (void)deleteItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row >= self.likedList.count) { return; } KBLikedCompanionModel *model = self.likedList[indexPath.row]; __weak typeof(self) weakSelf = self; [self.viewModel likeCompanionWithCompanionId:model.companionId completion:^(KBCommentLikeResponse * _Nullable response, NSError * _Nullable error) { dispatch_async(dispatch_get_main_queue(), ^{ if (error) { [KBHUD showError:error.localizedDescription]; return; } // 删除本地数据 if (indexPath.row < weakSelf.likedList.count) { [weakSelf.likedList removeObjectAtIndex:indexPath.row]; } if (indexPath.row < weakSelf.dataArray.count) { [weakSelf.dataArray removeObjectAtIndex:indexPath.row]; } [weakSelf.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft]; }); }]; } #pragma mark - Lazy Load - (AiVM *)viewModel { if (!_viewModel) { _viewModel = [[AiVM alloc] init]; } return _viewModel; } - (NSMutableArray *)likedList { if (!_likedList) { _likedList = [NSMutableArray array]; } return _likedList; } @end