2
This commit is contained in:
110
keyBoard/Class/AiTalk/VC/KBAIMessageZanVC.m
Normal file
110
keyBoard/Class/AiTalk/VC/KBAIMessageZanVC.m
Normal file
@@ -0,0 +1,110 @@
|
||||
//
|
||||
// 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<KBLikedCompanionModel *> *likedList;
|
||||
|
||||
@end
|
||||
|
||||
@implementation KBAIMessageZanVC
|
||||
|
||||
#pragma mark - Lifecycle
|
||||
|
||||
- (void)viewDidLoad {
|
||||
self.listType = 0; // Thumbs Up
|
||||
[super viewDidLoad];
|
||||
}
|
||||
|
||||
#pragma mark - 2:数据加载
|
||||
|
||||
- (void)loadData {
|
||||
[KBHUD show];
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.viewModel fetchLikedCompanionsWithCompletion:^(NSArray<KBLikedCompanionModel *> * _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<KBLikedCompanionModel *> *)likedList {
|
||||
if (!_likedList) {
|
||||
_likedList = [NSMutableArray array];
|
||||
}
|
||||
return _likedList;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user